Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Array Sort

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    New York
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array Sort

    If I have an array that looks like this:

    Code:
    pid[0]="Mike Smith"
    pid[1]="Joe Blow"
    pid[2]="Brian Slutsky"
    How can I sort it by name?
    -Stephen

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    As much as I hate the site... its what google found first:

    http://www.planet-source-code.com/vb...txtCodeId=6482

    And it should do what you want.
    OracleGuy

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by RadarBob; 07-31-2002 at 03:39 PM.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

    or

    myString = LCase(myString)
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I totally agree with raf. And if you're sorting on an indexed field, sorting should be particularly fast in SQL

  • #7
    New Coder
    Join Date
    Jul 2002
    Location
    New York
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks... for some reason it completely slipped my mind to use the ORDER BY statement while reading them into the array. Thanks.
    -Stephen


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •