Sorting TSTringList Names property as integers instead of strings [duplicate]

你离开我真会死。 提交于 2020-01-11 12:58:43

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/15423832/sorting-tstringlist-names-property-as-integers-instead-of-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!