I got this list of names in a textfile in a randomn order....how do I sort it in an alphabetical order (delphi) ? I need to keep it in the same text file. File looks like this:
Smith
Jack
Klein
Elliot
I got this list of names in a textfile in a randomn order....how do I sort it in an alphabetical order (delphi) ? I need to keep it in the same text file. File looks like this:
Smith
Jack
Klein
Elliot
I would use a TStringlist since it have a buildin function for sorting. Something like this:
var
Stringlist : TStringlist;
begin
Stringlist := TStringlist.Create;
StringList.Loadfromfile(MYFILE);
StringList.sort;
StringList.saveToFile(MYFILLE);
StringList.Free;
end;
If every word occupies separate line, the simplest way is to use StringList class (I save result in another file for safer debug)
with TStringList.Create do try
LoadFromfile('text.txt');
Sort;
SaveToFile('sortedtext.txt');
finally
Free;
end;