How to convert AnsiString to UnicodeString in Delphi XE4

18,394

Your code is already correct. It will convert from ANSI to UTF-16 with no loss of information.

Thus I conclude that the information is lost when you assign to the AnsiString variable. In other words, the error in your code is contained in the .... part of your code.

The error will likely be that the data and the code page of your AnsiString variable do not match.

Share:
18,394
taoxl
Author by

taoxl

Updated on June 05, 2022

Comments

  • taoxl
    taoxl almost 2 years
    exzample code:
    var
      str1 : String;
      str2 : AnsiString;
      ....
      str2 := ....;
      str1 := String(str2);  
    

    I converted such as above,but it didn't work.i found that some data lost in str1.is there a safe way to convert AnsiString to UnicodeString?