0

I have a large file of text data where each line looks like such

10005=08/18/09,No BS,25094,wrg1

and the data is out of order (i.e. the number before the equal sign)

I load this file into a StringList as Name Value pairs. The TStringList sort function does not of course because the numbers are strings and not integers.

How can i get these into order before loading them into the TStringList?

Is there a fast function that I perform the file on that returns a TStrings that I can assign to the TStringList?

thankx

TLama
  • 71,521
  • 15
  • 192
  • 348
JakeSays
  • 1,898
  • 6
  • 27
  • 39

1 Answers1

4
function StrCmpLogicalW(sz1, sz2: PWideChar): Integer; stdcall;
  external 'shlwapi.dll' name 'StrCmpLogicalW';

function MyCompare(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result := StrCmpLogicalW(PWideChar(List[Index1]), PWideChar(List[Index2]));
end;

Usage:

  StringList.CustomSort(MyCompare);
TLama
  • 71,521
  • 15
  • 192
  • 348
NGLN
  • 41,230
  • 8
  • 102
  • 186
  • @TLama No need to declare as `PWideChar`, see [this answer](http://stackoverflow.com/a/10437339/757830). – NGLN Mar 15 '13 at 07:31
  • I know that it's not required (hence the edit comment). The best I would use is `PCWSTR` if it were defined in Delphi. – TLama Mar 15 '13 at 07:36