Is it necessary to convert string to WideString in Delphi?

后端 未结 4 1169
梦谈多话
梦谈多话 2020-12-30 02:24

I found a Windows API function that performs \"natural comparison\" of strings. It is defined as follows:

int StrCmpLogicalW(
    LPCWSTR psz1,
    LPCWSTR p         


        
4条回答
  •  星月不相逢
    2020-12-30 03:08

    Use System.StringToOleStr, which is a handy wrapper around MultiByteToWideChar, see Gabr's answer:

    function AnsiNaturalCompareText(const S1, S2: string): integer;   
    var
      W1: PWideChar;
      W2: PWideChar;
    begin
      W1 := StringToOleStr(S1);
      W2 := StringToOleStr(S2);
      Result := StrCmpLogicalW(W1, W2);
      SysFreeString(W1);
      SysFreeString(W2);
    end;
    

    But then, Ian Boyd's solution looks and is much nicer!

提交回复
热议问题