What is the "correct" way to convert PAnsiChar to a unicode string?

What is the "correct" way to convert PAnsiChar to a unicode string?
http://stackoverflow.com/q/27857479/49925

Comments

  1. Back in the pre-Unicode days, it was MultiByteToWideChar/WideCharToMultiByte that was the go-to tools for code page and character set conversion. http://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/dd374130(v=vs.85).aspx Both require you to know the CP of the source/target.
    More info: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317752(v=vs.85).aspx

    ReplyDelete
  2. Lars Fosdal They work as well as ever, but are platform specific. For x-plat you use UnicodeFromLocaleChars and LocaleCharsFromUnicode

    ReplyDelete
  3. Please refer to my answer:

    rbstr := pastr; // assign PAnsiChar to RawByteString
      // assume text encoded as codepage 936
      // Note here: set 3rd param to false!
      SetCodePage(rbstr,936,false);
      ustr := string(rbstr);

    http://stackoverflow.com/questions/27857479/whats-the-correct-way-to-assign-pansichar-to-a-unicode-string/27873918#27873918

    ReplyDelete

Post a Comment