如何将使用Windows代码页1251编码的字符串转换为Unicode字符串 [英] How can I convert string encoded with Windows Codepage 1251 to a Unicode string
本文介绍了如何将使用Windows代码页1251编码的字符串转换为Unicode字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序接收的cyrllic字符串使用(我相信)下面的表:
The cyrllic string my app receives uses(I believe) the table below:
我相信,因为我测试的所有字符都符合这个表。
said I believe, because all the chars I tested fit this table.
我把这样的东西转换为一个字符串,这是unicode默认在我的delphi?
或者更好:在delphi中有一个现成的转换器,或者我应该写一个吗?
Question: How do I convert such thing to a string, which is unicode by default in my delphi? Or better yet: Is there a ready-to-use converter in delphi or should I write one?
推荐答案
如果您使用的是Delphi 2009或更高版本,则会自动完成:
If you are using Delphi 2009 or later, this is done automatically:
type
CryllicString = type AnsiString(1251);
procedure TForm1.FormCreate(Sender: TObject);
var
UnicodeStr: string;
CryllicStr: CryllicString;
begin
UnicodeStr := 'This is a test.'; // Unicode string
CryllicStr := UnicodeStr; // ...converted to 1251
CryllicStr := 'This is a test.'; // Cryllic string
UnicodeStr := CryllicStr; // ...converted to Unicode
end;
这篇关于如何将使用Windows代码页1251编码的字符串转换为Unicode字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文