View Full Version : Array Sort

07-27-2002, 07:05 AM
If I have an array that looks like this:

pid[0]="Mike Smith"
pid[1]="Joe Blow"
pid[2]="Brian Slutsky"

How can I sort it by name?

07-27-2002, 07:45 AM
As much as I hate the site... its what google found first:


And it should do what you want.

07-27-2002, 05:11 PM
Hint: My experience is that upper case letters get sorted ahead of lower case, thus "Xylophone" will be in front of "apple." I've gotten around this by using the toUpperCase() function in Javascript.

07-31-2002, 01:22 AM
Haven't run into that problem in ASP, but if it's an issue (which I don't have time to test at the moment, but if I remember correctly, it's not an issue), you can do the same thing in ASP... heck it's a good thing to know anyway:

myString = UCase(myString)


myString = LCase(myString)

07-31-2002, 08:36 AM
Another hint : use ASP for what it was ment, and SQL and database for what they were ment.

in 99.9% of the cases, you can sort your data before an array whas created with something like
"select * from table where state=1 order by name desc"

like this you can choose the variable and the order (ascending or descending) If you pull it out of a DB, go SQL.

07-31-2002, 03:43 PM
I totally agree with raf. And if you're sorting on an indexed field, sorting should be particularly fast in SQL

08-01-2002, 05:49 AM
Thanks... for some reason it completely slipped my mind to use the ORDER BY statement while reading them into the array. Thanks.