将字符串从某些代码页转换为Unicode [英] conversion of a string from some codepage to 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
.
-
我认为
AnsiString
是MySource1253
的适当类型,而String
应该适用于MyUnicodeTarget 代码>,如果我错了,请纠正我.
I presume
AnsiString
to be the appropriate type forMySource1253
, whileString
should be suitable forMyUnicodeTarget
, 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屋!