amit 3 Posted June 21, 2023 I have strings in the TStringlist as follows ABC10 ABC1 ABC2 ABC21 I sort it using TStringlist.sort then I got the sorted result as ABC1 ABC10 ABC2 ABC21 But I need to have the results after sort as follows ABC1 ABC2 ABC10 ABC21 Is it possible to do that? Share this post Link to post
David Heffernan 2345 Posted June 21, 2023 https://stackoverflow.com/questions/5134712/how-to-get-the-sort-order-in-delphi-as-in-windows-explorer 2 Share this post Link to post
Remy Lebeau 1394 Posted June 21, 2023 (edited) 16 hours ago, amit said: Is it possible to do that? Yes, simply use TStringList.CustomSort() to sort the strings however you want, eg: function MySortFunc(List: TStringList; Index1, Index2: Integer): Integer; begin Result := StrToInt(Copy(List[Index2], 4, MaxInt)) - StrToInt(Copy(List[Index1], 4, MaxInt)); end; ... var SL: TStringList; SL := TStringList.Create; ... SL.Add('ABC10'); SL.Add('ABC1'); SL.Add('ABC2'); SL.Add('ABC21'); SL.CustomSort(@MySortFunc); ... SL.Free; Edited June 21, 2023 by Remy Lebeau 2 Share this post Link to post
programmerdelphi2k 237 Posted June 21, 2023 (edited) sorry, all wrong !!! Edited June 22, 2023 by programmerdelphi2k Share this post Link to post
programmerdelphi2k 237 Posted June 22, 2023 @amit try my sample https://en.delphipraxis.net/topic/9276-my-tstringlist-custom-sorting-trying-to-mimic-windows-explorer-way/ 1 Share this post Link to post