【发布时间】:2018-06-05 15:08:05
【问题描述】:
我有一个表示为字节数组的字符串,我知道该字符串已删除了0x00 的高位字节,因此该字符串被压缩为:
0x43 0x6F 0x6D 0x6D 0x61 0x6E 0x64 //"Command"
如何将字节转换为 Unicode 字符串?
我猜我需要每隔一秒将字节复制到一个大小为两倍的新数组 (uncompressedBytes) 中:
byte[] compressedBytes = br.ReadBytes(stringLength);
byte[] uncompressedBytes = new byte[stringLength * 2];
for (int byteCounter = 0; byteCounter < stringLength; byteCounter++)
{
uncompressedBytes[byteCounter * 2] = compressedBytes[byteCounter];
}
return Encoding.Unicode.GetString(uncompressedBytes);
或者是否有一种编码将所有字节视为缺少高位字节的 Unicode 字符?
【问题讨论】:
标签: c# arrays string unicode character-encoding