求能不能实现输入多个汉字后转换成汉字区位码呢?代码是单个汉字的~
private string strCode(char charOne)
{
Encoding unicode = Encoding.Unicode;
Encoding gb2312 = Encoding.GetEncoding(936);
byte[] unicodeBytes = unicode.GetBytes(new Char[] { charOne });
byte[] asciiBytes = Encoding.Convert(unicode, gb2312, unicodeBytes);
int n = (int)asciiBytes[0] << 8;
n += (int)asciiBytes[1];
return n.ToString();
}
------解决方案--------------------
C# code
string str = "斯拉夫登陆了";
StringBuilder sb = new StringBuilder();
foreach(char c in str)
{
sb.Append(strCode(c));
}
Console.WriteLine(sb.ToString());