如何将Unicode值转换为其等效的字符串?
例如,我有"రమెశ్",我需要一个函数来接受这个Unicode值并返回一个字符串。
我正在研究System.Text.Encoding.Convert()函数,但它不接受Unicode值;它接受两种编码和一个字节数组。
我基本上有一个字节数组,我需要将它保存在字符串字段中,然后再回来,首先将字符串转换回字节数组。
因此,我使用ByteConverter.GetString(byteArray)将字节数组保存为字符串,但无法将其恢复为字节数组。
发布于 2013-12-12 01:24:27
使用.ToString();
this.Text = ((char)0x00D7).ToString();发布于 2010-11-15 20:22:34
尝试以下操作:
byte[] bytes = ...;
string convertedUtf8 = Encoding.UTF8.GetString(bytes);
string convertedUtf16 = Encoding.Unicode.GetString(bytes); // For UTF-16另一种方法是使用` `GetBytes():
byte[] bytesUtf8 = Encoding.UTF8.GetBytes(convertedUtf8);
byte[] bytesUtf16 = Encoding.Unicode.GetBytes(convertedUtf16);在Encoding类中,如果您需要的话,还有更多的变体。
发布于 2012-07-28 00:42:24
要将字符串转换为Unicode字符串,请执行以下操作:非常简单...请注意BytesToString函数,它避免使用任何内置的转换内容。速度也很快。
private string BytesToString(byte[] Bytes)
{
MemoryStream MS = new MemoryStream(Bytes);
StreamReader SR = new StreamReader(MS);
string S = SR.ReadToEnd();
SR.Close();
return S;
}
private string ToUnicode(string S)
{
return BytesToString(new UnicodeEncoding().GetBytes(S));
}https://stackoverflow.com/questions/4184190
复制相似问题