1

我正在寻找将 UTF8(孟加拉语字符)转换为 UCS2 字节数组的代码示例。我有直接的方法来解决这个问题吗?不知何故,我得到了 UCS2 转换,但不是在字节数组中的字符串值。

例如:

byte[] message;
message = UTF2UCS.GetBytes
          ( smsText.Substring(0, 
           smsText.Length > maxLength ? maxLength : smsText.Length)); 

我的返回输出应该是这样的。

谢谢

4

3 回答 3

2

像这样的东西是你能得到的最好的。根据此链接

//1200  Unicode UCS-2 Little-Endian (BMP of ISO 10646)
//1201  Unicode UCS-2 Big-Endian

Encoding bytesUCS = Encoding.GetEncoding(1201);
Encoding utf8 = Encoding.UTF8;
byte[] utf8Bytes = utf8.GetBytes(UTF2UCS);
byte[] isoBytes = Encoding.Convert(utf8, bytesUCS, utf8Bytes);
于 2015-06-08T11:46:24.387 回答
1
 byte[] utcs2Bytes = System.Text.Encoding.Convert(System.Text.Encoding.UTF8, System.Text.Encoding.Unicode, newArray);

newArray 是用于存储编码字节的目标字节数组

于 2015-06-25T04:44:17.750 回答
-1

使用Encoding.GetBytesEncoding.GetString

byte[] bengaliUtf8 = ....
string stringValue = UTF8Encoding.GetString(bengaliUtf8);
byte[] utf16Value = UnicodeEncoding.GetBytes(stringValue);

UTF-16 ('Unicode') 是你能得到的最好的,C# 不支持 UCS-2。如果您的输入没有代理字符,则 UTF-16 的输出与 UCS-2 匹配。

于 2015-06-08T11:42:58.867 回答