SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Member
    Join Date
    Sep 2010
    Location
    TN, India
    Posts
    377
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Sorting array contents like Windows Sorting

    Hi all,

    I want to sort a array using JavaScript. The array contains file names listed in a directory in windows OS computer. I have sorted my folder by Name and have to verify its sorted by name only or not?
    For this, I am taking the file names as an array and sorting using JavaScript array and verifying back with files available in my folder in order.

    But JavaScript sort not sorting as expected. Its sorting like string content. But windows OS will sort the files based on chars and numbers in file names like..
    If I have files "@abcd", "abcd12", "abcd2" in a folder. Now windows Name sort will order these files as
    "@abcd", "abcd2" and then "abcd12". But JavaScript sort will not give this order.
    I want to sort an array using some windows API that will sort as windows sorting. Can anybody give me ideas?
    What DLL we can use?

    Thanks...
    Thank/Like to help others if my input helped you !!!
    I am speaking for myself, not for my employer nor any one.
    Automation Ecstasy

  2. #2
    Senior Member
    Join Date
    Jul 2008
    Posts
    1,049
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Hi Shanmugavel,

    I'm not sure whether the comparison/sorting routine is available somewhere in the API, however, note that you can write a script routine which will perform the comparison as necessary and pass the routine as an argument to the "sort" method in order to make the sort method use your custom routine for array items comparison. Please see the following page for more information:
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    Regards,
    Allen - SmartBear Support

  3. #3
    Member
    Join Date
    Sep 2010
    Location
    TN, India
    Posts
    377
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Hi allen,

    Thanks...
    Actually I tried these kind of sorting functions already. Any other methods?


    Thanks...
    Thank/Like to help others if my input helped you !!!
    I am speaking for myself, not for my employer nor any one.
    Automation Ecstasy

  4. #4
    Member
    Join Date
    Sep 2008
    Location
    India
    Posts
    422
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Hi,

    Could you post what order javascript sort returns?
    Are you create your own function for sorting or you are using some inbuilt function or utility?
    ~Vivek
    -------------------------------------------
    Software Testing Interview Question and Answer
    --------------------------------------------

  5. #5
    Member
    Join Date
    Sep 2010
    Location
    TN, India
    Posts
    377
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Hi Vivek,
    I am using Inbuilt JavaScript function like,
    sort(function(a, b){return a-b}) and
    sort(function(a, b){return (f > c ? 1f < c ? -1 : 0)})
    Its taking my file names as full string and it will return in order "@abcd", "abcd12", "abcd2".

    But I want windows order.

    Thanks...
    Thank/Like to help others if my input helped you !!!
    I am speaking for myself, not for my employer nor any one.
    Automation Ecstasy

  6. #6
    Member
    Join Date
    Sep 2008
    Location
    India
    Posts
    422
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Hi,

    i am trying same thing to implement and it would return me the same result as windows sort. i have implemented this in js file.
    ~Vivek
    -------------------------------------------
    Software Testing Interview Question and Answer
    --------------------------------------------

  7. #7
    Member
    Join Date
    Sep 2010
    Location
    TN, India
    Posts
    377
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Thanks vivek...

    Can you share me the piece of code from your JS file?

    Thanks...
    Thank/Like to help others if my input helped you !!!
    I am speaking for myself, not for my employer nor any one.
    Automation Ecstasy

  8. #8
    Senior Member
    Join Date
    Jul 2008
    Posts
    1,049
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Hi Shanmugavel,

    If you don't get the script you need, we can try to investigate this. Since char codes are used for sorting, I suppose the difference between the sorting orders is in char codes assigned to some characters. A quick search on the web does not return any useful results, but I suppose that the differences are caused by encoding. In order to investigate this, we'll need to have a number of specific examples demonstrating differences in sorting order between Windows and JScript.
    Regards,
    Allen - SmartBear Support

  9. #9
    Member
    Join Date
    Sep 2010
    Location
    TN, India
    Posts
    377
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Let me here give some examples for better understanding for how windows and script sorts.

    Windows Order / JavaScript Order
    ------------------------------ / --------------------------------
    Eg1:
    !@#$.doc / a.doc
    '!@'.doc / a1.doc
    a.doc / a10.doc
    a1.doc / a2.doc
    a2.doc / c.doc
    a10.doc / !@#$.doc
    c.doc / '!@'.doc

    Eg2:
    '!@#$%^&*'.doc / a.doc
    !@#$%'.doc / a1.doc
    a.doc / a10.doc
    a1.doc / a2.doc
    a2.doc / c.doc
    a10.doc / !@#$.doc
    c.doc / '!@#$%^&*'.doc

    Hope this helps!
    Thank/Like to help others if my input helped you !!!
    I am speaking for myself, not for my employer nor any one.
    Automation Ecstasy

  10. #10
    Senior Member
    Join Date
    Jul 2008
    Posts
    1,049
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Sorting array contents like Windows Sorting

    Hi Shanmugavel,

    I see. So, there are two differences:
    1. Special characters codes (lower numbers in Windows, higher numbers in JavaScript).
    2. String length has precedence in Windows, while JScript puts character codes first.

    We will look into this and try to create a sample code for the comparison. Note, however, that custom samples creation is not a high-priority task for us, so this can take some time.
    Regards,
    Allen - SmartBear Support

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 08:19 AM.

Copyright BetaSoft Inc.