将TSTringList Names属性排序为整数而不是字符串 [英] Sorting TSTringList Names property as integers instead of strings
本文介绍了将TSTringList Names属性排序为整数而不是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很大的文本数据文件,每行看起来像这样
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)
我将此文件作为名称/值对加载到StringList中。当然,TStringList排序功能不是因为数字是字符串而不是整数。
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.
在将它们加载到TStringList之前,如何使它们井然有序?
How can i get these into order before loading them into the TStringList?
执行文件的快速函数是否返回可以分配给TStringList的TString?
Is there a fast function that I perform the file on that returns a TStrings that I can assign to the TStringList?
thankx
推荐答案
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;
用法:
StringList.CustomSort(MyCompare);
这篇关于将TSTringList Names属性排序为整数而不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文