//test.txt 的文本:\u5fc3\u810f\u75c5\u5b66 StreamReader sr = new StreamReader("..\\test.txt",System.Text.Encoding.Default);//.Unicode); string s = sr.ReadToEnd(); s = s.Replace(@"\u",""); int count = s.Length / 4; byte[] buf = new byte[count * 2]; System.Text.Encoding.Default.GetBytes(s); MemoryStream ms = new MemoryStream(buf); int i; BinaryWriter w = new BinaryWriter(ms,System.Text.Encoding.Default); for (i = 0 ; i < count; ++i) { short n = short.Parse(s.Substring(i * 4,4),System.Globalization.NumberStyles.HexNumber); w.Write(n); } w.Close(); string ss = System.Text.Encoding.Unicode.GetString(buf); this.label1.Text = ss;
PS:哥们学医的?
我的要求是把字符串放在一个textbox里,然后在label里显示对应的中文。
byte[] byteArray = encoding.GetBytes("\u5fc3\u810f\u75c5\u5b66");
string str = System.Text.Encoding.GetEncoding("GB2312").GetString(byteArray);
StreamReader sr = new StreamReader("..\\test.txt",System.Text.Encoding.Default);//.Unicode);
string s = sr.ReadToEnd();
s = s.Replace(@"\u","");
int count = s.Length / 4;
byte[] buf = new byte[count * 2];
System.Text.Encoding.Default.GetBytes(s);
MemoryStream ms = new MemoryStream(buf);
int i;
BinaryWriter w = new BinaryWriter(ms,System.Text.Encoding.Default);
for (i = 0 ; i < count; ++i)
{
short n = short.Parse(s.Substring(i * 4,4),System.Globalization.NumberStyles.HexNumber);
w.Write(n);
}
w.Close();
string ss = System.Text.Encoding.Unicode.GetString(buf);
this.label1.Text = ss;