Thread: Sorting strings

  1. #1

    Sorting strings

    What's the best way for me to sort strings? I'm using LPSTR.

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    Depends on why you are sorting them.
    If it's because you need to have an order, but don't care which (so you can later search for them with a binary search) then lexicographical_compare or strcmp will be pretty similar in their results.
    If it's to present them in order to a user then you need to sort them according to their culture's rules. You could use lexicographical_compare along with a locale-specific comparison object, or (since this is the Windows Programming section) you could go with the CompareString API.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    http://www.unicode.org/reports/tr10/ is worth a read if you want to get deep into the details of rolling your own locale-specific comparisons.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem sorting an array of strings
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 05-07-2008, 09:02 PM
  2. strings, sorting
    By kocika73 in forum C Programming
    Replies: 4
    Last Post: 02-18-2006, 03:29 PM
  3. Replies: 2
    Last Post: 02-23-2004, 05:34 AM
  4. bubble sorting multiple strings
    By jibbles in forum C Programming
    Replies: 10
    Last Post: 10-11-2003, 11:48 PM
  5. Sorting strings to speed up search?
    By Mox in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2001, 12:17 PM