如何将使用Windows Codepage 1251编码的字符串转换为Unicode字符串 [英] How can I convert string encoded with Windows Codepage 1251 to a Unicode string

查看:889
本文介绍了如何将使用Windows Codepage 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.

问题:怎么做我将这样的东西转换成一个字符串,默认情况下在我的delphi中是unicode?
还是更好: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
  CyrillicString = type AnsiString(1251);

procedure TForm1.FormCreate(Sender: TObject);
var
  UnicodeStr: string;
  CyrillicStr: CyrillicString;
begin
  UnicodeStr := 'This is a test.'; // Unicode string
  CyrillicStr := UnicodeStr; // ...converted to 1251

  CyrillicStr := 'This is a test.'; // Cryllic string
  UnicodeStr := CyrillicStr; // ...converted to Unicode
end;

这篇关于如何将使用Windows Codepage 1251编码的字符串转换为Unicode字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆