eee.text = "\u84b2\u5df4\u7532"; 能显示汉字
但是 string aa = "\u84b2\u5df4\u7532";
eee.text =aa; 显示的就是"\u84b2\u5df4\u7532"怎么把它转变成汉字,赋值到变量中呢?
但是 string aa = "\u84b2\u5df4\u7532";
eee.text =aa; 显示的就是"\u84b2\u5df4\u7532"怎么把它转变成汉字,赋值到变量中呢?
"\u84b2\u5df4\u7532"也确是一个string
换个什么类型吧 具体没搞过
你的eee是什么?我这里是textbox
string aa = "\\u84b2\\u5df4\\u7532"
textbox1.text = aa ;
显示的是汉字?
{
//textBox1.Text = "\u84b2\u5df4\u7532";
aa = "\u84b2\u5df4\u7532";
textBox1.Text = aa;
}
读到一个变量以后 自动就变成 “\\u84b2\\u5df4\\u7532”
我尝试用 aa.Replace("\\\\u", "\\u").ToString();但是无效
不明白怎么会自动变成“\\u84b2\\u5df4\\u7532”这样的,你是怎么读的?反正“\u84b2\u5df4\u7532”这样赋值给变量后出来的肯定是汉字不会错。
我通过正则处理后想得到引号内的部分。
Regex regexTerm = new Regex(textBox1.Text, RegexOptions.IgnoreCase);
Match matchTerm = regexTerm.Match(textBox5.Text);
while (matchTerm.Success)
{
string aa = matchTerm.Groups[1].Value.ToString();
string bb = matchTerm.Groups[2].Value.ToString(); //这是是我的到的 但值变成了"\\u84b2\\u5df4\\u7532"
textBox2.Text = aa + "\r\n"
+ "08-06-01\u65b0\u95fb\u7efc\u5408\u9891\u9053\u84b2\u84b2\u9732\u4e00\u5c0f\u8138"; matchTerm = matchTerm.NextMatch();
}不知道怎么回事,程序把原字符串中的“\u”看成了是2个字符,而不是UFT-8的转义符好。
private void button8_Click(object sender, EventArgs e)
{
Regex regexTerm = new Regex(@"(.*):""([^""]+)""", RegexOptions.IgnoreCase);
Match matchTerm = regexTerm.Match(textBox5.Text);
while (matchTerm.Success)
{
string aa = matchTerm.Groups[1].Value.ToString();
string bb = matchTerm.Groups[2].Value.ToString(); //这是是我的到的 但值变成了"\\u84b2\\u5df4\\u7532"
textBox2.Text = aa + "\r\n" + bb + "\r\n"
+ "08-06-01\u65b0\u95fb\u7efc\u5408\u9891\u9053\u84b2\u84b2\u9732\u4e00\u5c0f\u8138"; matchTerm = matchTerm.NextMatch(); }
}然后就会出现 我说的这种情况了 其实在textBox5.text里的字符串以及发生变化
这是编译时字符串转义,实际运行时字符串中已经是汉字//但是 string aa = "\u84b2\u5df4\u7532";
//eee.text =aa; 显示的就是"\u84b2\u5df4\u7532"
这是运行时字符串编码,实际就是\u84b2\u5df4\u7532
要变成汉字,需要每4位截取字符串,
然后进行编码转换(按16进制转为数字,再强制转为char)
textBox5.Text ="aa:\"\u84b2\u5df4\u7532\"";
和在控件testBox5的Text属性写入aa:"\u84b2\u5df4\u7532" 是不同的;
后者实际的字符串是 aa:\"\\u84b2\\u5df4\\u7532\" 但在用户界面显示的是相同的。
为什么会这样呢?怎么处理呢?
string str = "";
string[] arr = aa.Split( new char[2] { '\\', 'u' }, StringSplitOptions.RemoveEmptyEntries );
foreach ( string s in arr )
{
str += (char)Convert.ToInt32( s, 16 );
}
string[] arr = aa.Split( new char[2] { '\\', 'u' }, StringSplitOptions.RemoveEmptyEntries );
意思是先\\分割 然后删除u?