taoxl
taoxl

Reputation: 135

How to convert AnsiString to UnicodeString in Delphi XE4

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?

Upvotes: 3

Views: 21736

Answers (1)

David Heffernan
David Heffernan

Reputation: 613451

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.

Upvotes: 5

Related Questions