Board index » delphi » Sorting alphabetically

Sorting alphabetically

Is there any easy way to sort a stringlist alphabetically?
I know how to sort a stringlist when it only contains numbers.
So what I really am asking is: is there any way to do this:
if  'test' "is before in the alphabet than" ' another test' then ...
--
____________________________________________
Morten Goodwin Olsen
                   Homepage: http://members.xoom.com/Mgo
                           E-mail: m...@vf.telia.no

 

Re:Sorting alphabetically


Morten:

Quote
Morten Goodwin Olsen wrote in message <3578805...@d2o210.telia.com>...
>Is there any easy way to sort a stringlist alphabetically?
>I know how to sort a stringlist when it only contains numbers.
>So what I really am asking is: is there any way to do this:
>if  'test' "is before in the alphabet than" ' another test' then ...

This answer is slightly different than what you're asking, but
it might be of interest to you.

The ListSort example on the Other Projects page of my Computer Lab
shows how to sort a TList of user-defined TNodes using the Sort
method of the TList and a user-defined function that controls
the comparison of items in the TList.

efg
_________________________________________
efg's Computer Lab:  http://infomaster.net/external/efg

Earl F. Glynn                 E-Mail:  EarlGl...@att.net
MedTech Research Corporation, Lenexa, KS  USA

Re:Sorting alphabetically


In article <3578805...@d2o210.telia.com>, "Morten Goodwin Olsen"

Quote
<m...@vf.telia.no> writes:
>Is there any easy way to sort a stringlist alphabetically?
>I know how to sort a stringlist when it only contains numbers.
>So what I really am asking is: is there any way to do this:
>if  'test' "is before in the alphabet than" ' another test' then ...

TStringList.Sort;

 . . . or do you mean "How do I implement a non-alphabetical sort" - if so you
would have to write your own sort procedure using TStringList.Exchange to swap
TStringList strings as appropriate until it was sorted.

ie in pseudo-code

repeat
  set finished flag to true
  for first string to last but one string
    if LessThan(this-string, next string) then
     swap this-string and next-string, and set finished flag to false
until finished

function LessThan(this-string, next-string);
{returns true if this-string is less than next-string by your definitions}

Alan Lloyd
alangll...@oal.com

Re:Sorting alphabetically


Quote
Morten Goodwin Olsen wrote:

> Is there any easy way to sort a stringlist alphabetically?
> I know how to sort a stringlist when it only contains numbers.
> So what I really am asking is: is there any way to do this:
> if  'test' "is before in the alphabet than" ' another test' then ...
> --

StringList.Sorted :=true; ???

Pascal
--------------------------------------------------------------------
{*word*137} software engineer

ing. Pascal Dutilleul
Pascal.Dutill...@ping.be                  Borland Connections Member
--------------------------------------------------------------------

Other Threads