如何才能统一code值转换为其对应的字符串?
How can I convert a Unicode value to its equivalent string?
例如,我有రమెశ్,我需要接受这种统一code值,并返回一个字符串的函数。
For example, I have "రమెశ్", and I need a function that accepts this Unicode value and returns a string.
我一直在寻找在System.Text.Encoding.Convert()函数,但是,这并不需要在一个统一code值;它需要两个编码和字节数组。
I was looking at the System.Text.Encoding.Convert() function, but that does not take in a Unicode value; it takes two encodings and a byte array.
我bascially有我需要保存在一个字符串字段,然后回来后和字符串转换先回一个字节数组的字节数组。
I bascially have a byte array that I need to save in a string field and then come back later and convert the string first back to a byte array.
所以我用ByteConverter.GetString(字节阵列)的字节数组保存到一个字符串,但我不能让它回到一个字节数组。
So I use ByteConverter.GetString(byteArray) to save the byte array to a string, but I can't get it back to a byte array.
请尝试以下操作:
byte[] bytes = ...;
string convertedUtf8 = Encoding.UTF8.GetString(bytes);
string convertedUtf16 = Encoding.Unicode.GetString(bytes); // For UTF-16
周围使用'的GetBytes()的另一种方式:
The other way around is using `GetBytes():
byte[] bytesUtf8 = Encoding.UTF8.GetBytes(convertedUtf8);
byte[] bytesUtf16 = Encoding.Unicode.GetBytes(convertedUtf16);
在编码
类,也有更多的变种,如果你需要他们。
In the Encoding
class, there are more variants if you need them.
上一篇:什么是SQL Server的用户实例的非dev的箱子(与CE等嵌入式数据库)?箱子、嵌入式、实例、数据库
下一篇:的WinForms:Form.FromHandle返回加载到.NET可执行文件code过程主要形式空可执行文件、加载、形式、过程