Is it necessary to convert string to WideString in Delphi?

后端 未结 4 1170
梦谈多话
梦谈多话 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 02:51

    Keep in mind that casting a string to a WideString will convert it using default system codepage which may or may not be what you need. Typically, you'd want to use current user's locale.

    From WCharFromChar in System.pas:

    Result := MultiByteToWideChar(DefaultSystemCodePage, 0, CharSource, SrcBytes,
      WCharDest, DestChars);
    

    You can change DefaultSystemCodePage by calling SetMultiByteConversionCodePage.

提交回复
热议问题