Sorting strings

This is a discussion on Sorting strings within the Windows Programming forums, part of the Platform Specific Boards category; What's the best way for me to sort strings? I'm using LPSTR....

  1. #1
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293

    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, 10:02 PM
  2. strings, sorting
    By kocika73 in forum C Programming
    Replies: 4
    Last Post: 02-18-2006, 04:29 PM
  3. Replies: 2
    Last Post: 02-23-2004, 06:34 AM
  4. bubble sorting multiple strings
    By jibbles in forum C Programming
    Replies: 10
    Last Post: 10-12-2003, 12:48 AM
  5. Sorting strings to speed up search?
    By Mox in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2001, 01:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21