unicode码转和 中文之间的转换

1. 将unicode码转换为 汉字:

  

View Code
1             string [] chs = TextBox1.Text.Replace('\\',' ').Split('u');
2 StringBuilder sb = new StringBuilder();
3 for (int i = 1; i < chs.Length; i++)
4 {
5 int data = Convert.ToInt32(chs[i].ToString().Trim(),16);
6 sb.Append((char)data);
7 }
8 Response.Write(sb.ToString());

   也可以通过javascript 来转换:

var ss = $("#t2").val(); //获取值
ss = ss.replace(/\\/g, '%'); //将 \ 用% 替换 g/代表全部替换
var v = unescape(ss); //解码

2. 将汉字转换为unicode码:

  

View Code
            StringBuilder unicode = new StringBuilder();
string zhStr = TextBox1.Text;
for (int i = 0; i < zhStr.Length; i++)
{
char c = zhStr[i];
unicode.Append("\\u" + Convert.ToString(c,16));
}
Response.Write(unicode.ToString());

   脚本转换: var v = escape(document.getElementById("t2").value);

 

示例数据:\u63d0\u9192\u4f60  对应中文为:提醒你

你可能感兴趣的:(unicode)