Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Array of String alpha sort

Status
Not open for further replies.

ozhiker

Programmer
Sep 10, 2002
3
AU
Hi,

I have an array of strings that represent filenames and I
need to sort these, I understand how to sort a group of integers numerically, but how do u sort stings? Any help would be much appreciated.

 
The same way you sort the integers

ABC is less then BEF Steven van Els
SAvanEls@cq-link.sr
 
Create a TStringList, put all your strings in it, and use its Sort or CustomSort method:
Code:
var myStringArray: array [0..99] of string;
var myStringList: TStringList;
begin
  myStringList := TStringList.Create;
  for I := 0 to 99 do
    myStringList.Add(myStringArray[I]);

  myStringList.Sort;
  // then use the sorted list for whatever, then:
  myStringList.Free;
end;
See help on TStringList and TStringList.Sort for more details.

In this example, I've assumed that your strings start in an array, and so I've copied them into the StringList. But there's no reason to ever use an array; you can just use the StringList right from the start. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top