将字符串从某些代码页转换为Unicode [英] conversion of a string from some codepage to Unicode

查看:114
本文介绍了将字符串从某些代码页转换为Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将CP-1253字符串转换为Unicode,并且还要执行相反的转换.

I would like to convert a CP-1253 string to Unicode and also perform the opposite conversion as well.

假设我有两个保存字符串的变量,一个 MySource1253 和一个 MyUnicodeTarget .

Suppose I have two variables holding the strings, a MySource1253 and a MyUnicodeTarget.

  1. 我认为 AnsiString MySource1253 的适当类型,而 String 应该适用于 MyUnicodeTarget ,如果我错了,请纠正我.

  1. I presume AnsiString to be the appropriate type for MySource1253, while String should be suitable for MyUnicodeTarget, please correct me if I am wrong.

Delphi XE中是否有一些功能可以将这些转换从一个转换到另一个,反之亦然?

Is there some function in Delphi XE to make these conversions from one to the other and vice versa?

推荐答案

声明:

type
  GreekString = type Ansistring(1253);

要在它们之间进行转换,只需使用以下代码:

And to convert between them, just use following code:

var
  UnicodeStr: string;
  GreekStr: GreekString;
begin
  UnicodeStr := 'This is a test.'; // Unicode string
  GreekStr := GreekString(UnicodeStr); // ...converted to 1253

  GreekStr := 'This is a test.'; // Greek string
  UnicodeStr := string(GreekStr); // ...converted to Unicode
end;

另请参见:如何将使用Windows Codepage 1251编码的字符串转换为Unicode字符串.

这篇关于将字符串从某些代码页转换为Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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