PDA

View Full Version : Lower case or Upper Case problem for sorting an array


Avatarye
01-02-2008, 01:30 PM
I'm working on a script which creates an array for all files and sub-dir in a certain folder. After I got the array and used "sort" to sort all the items in alphabetic order, I just found all items start with a lower case letter come after all item with upper case. Here's an example:

a = #("A","B","C","a","b","c")
sort a
a = #("A","B","C","a","b","c")

My question is that is it possbile to sort array "a" in an alphabetic order regardless upper or lower case. Thanks a lot for the help!

U.S.S. Speed
01-02-2008, 06:00 PM
I would say the function you seek may be qsort instead of sort.

RustyKnight
01-02-2008, 10:44 PM
I'm working on a script which creates an array for all files and sub-dir in a certain folder. After I got the array and used "sort" to sort all the items in alphabetic order, I just found all items start with a lower case letter come after all item with upper case. Here's an example:

a = #("A","B","C","a","b","c")
sort a
a = #("A","B","C","a","b","c")

My question is that is it possbile to sort array "a" in an alphabetic order regardless upper or lower case. Thanks a lot for the help!Yep, qSort would be the key...but the question is why...?

qSort allows you to pass in the function that is used as element-by-element comparison, which would allow you to perform a non-case sensitive comparison...

Shane

Avatarye
01-03-2008, 05:41 AM
Thanks, U.S.S. Speed and RustyKnight. I've solved the problem with qsort like this:

fn stringCmpFN s1 s2 = stricmp s1 s2
qsort a stringCmpFN

then I got the result i want:

a = #("a", "A", "b", "B", "c", "C")

The goal is to create a tree view of certain folder on hardriver and all subdir should be sorted insensitive to upper or lower case. Thanks again.

CGTalk Moderation
01-03-2008, 05:41 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.