function MyNormalizeString(AStr: string; AValLength: byte = 10): string; var LStr: string; LVal: string; LEnd: integer; begin LStr := ''; LVal := ''; LEnd := AStr.Length; // { ex. Text1 and Text1234567890 and Text123456789012345 = part complex!!! AValLength := ? Text0000000001 Text1234567890 Text123456789012345 // ... we can have it with distinct length, then let's use an arbitrary value! } if (AValLength < 10) then AValLength := 10 else if (AValLength > 20) then AValLength := 20; // for var i: integer := 1 to LEnd do begin if CharInSet(AStr[i], LMyDigits) then begin LVal := LVal + AStr[i]; // if ((i + 1) <= LEnd) and not(CharInSet(AStr[i + 1], LMyDigits)) then begin LStr := LStr + DupeString('0', AValLength - LVal.Length) + LVal; LVal := ''; end; end else LStr := LStr + AStr[i]; end; // if not LVal.IsEmpty then LVal := DupeString('0', AValLength - LVal.Length) + LVal; // result := LStr + LVal; end;
end.
------- my Form1 tests: //...
type TForm1 = class(TForm) Btn_CustomSort: TButton; Memo1: TMemo; Btn_NO_ORDer: TButton; procedure Btn_CustomSortClick(Sender: TObject); procedure Btn_NO_ORDerClick(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
uses uMyTools;
function MyStringListCustomSort(SL: TStringList; ALeft, ARight: integer): integer; var LCLeft, LCRight : string; CmpLeft, CmpRight: string; begin LCLeft := LowerCase(SL[ALeft]); LCRight := LowerCase(SL[ARight]); // CmpLeft := MyNormalizeString(LCLeft); CmpRight := MyNormalizeString(LCRight); // result := CompareStr(CmpLeft, CmpRight); // if (result = 0) then result := CompareStr(LCLeft, LCRight); end;
procedure MyStringListADDs(var ASL: TStringList); begin ASL.Add('Delphi1World1Hello Windows'); // 1 space ASL.Add('hello2'); ASL.Add('hello10'); ASL.Add('hello1'); ASL.Add('hello4'); ASL.Add('delphi 2'); // 2 spaces ASL.Add('hello 000'); // 1 space ASL.Add('delphi'); ASL.Add('hello3'); ASL.Add('Delphi3 World2023'); // 1 space ASL.Add('Custom'); ASL.Add('delphi 2'); // 1 space ASL.Add('Delphi1.5World10 11'); // 1.5 - 1 space ASL.Add('World'); ASL.Add('Delphi 1'); // 1 space ASL.Add('A B C'); // 1 space + 1 space ASL.Add('hello000'); // 0 space ASL.Add('abc'); ASL.Add('delphi 2'); // 1 space ASL.Add(''); // EMPTY!!! ASL.Add('Delphi10'); ASL.Add('Delphi1'); ASL.Add('Delphi13'); ASL.Add('Delphi1.5World10 21'); // 1.5 - 1 space ASL.Add('Delphi001'); ASL.Add('Delphi3'); ASL.Add('Delphi3World2023'); ASL.Add('Delphi3 Hi!'); // 1 space ASL.Add('Delphi 5'); // 1 space ASL.Add('Delphi1.2World1Hello Windows'); // 1 space ASL.Add('Delphi2'); ASL.Add('Delphi01'); ASL.Add('Delphi 3World2023'); // 1 space ASL.Add('Delphi 1'); // 1 space ASL.Add('Delphi12'); ASL.Add('Delphi4'); ASL.Add('Delphi2.5World2022'); // 2.5 ASL.Add('Hello3.5'); end;
using StrCmpLogicalW + ShlWApi.dll = high dependence on MSWindows platform! --- NOT cross-platform!
my simple sample is cross-platform = no dependences!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
in my tests, the result is the same between my-code...StrCmpLogicalW
... of course, needs more "intensity" on tests...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3