unicode字符

unicode字符
如果是这样的string str = "\u5317\u4eac";
那直接输出就可以了
如果这个字符串是从其它地方得到的话,就这样:
C# code
 
 
 
 

 
 
 
  
  
  
  
string str = " \\u5317\\u4eac " ; string [] temp = str.Split( new string [] { " \\u " }, StringSplitOptions.RemoveEmptyEntries); for ( int i = 0 ; i < temp.Length; i ++ ) temp[i] = (( char )Convert.ToInt32(temp[i], 16 )).ToString(); string result = string .Join( "" , temp); Console.WriteLine(result);
要从汉字转成unicode编码:
C# code
  
  
  
  

  
  
  
   
   
   
   
string str = " 北京 " ; StringBuilder sb = new StringBuilder(); foreach ( char c in str) sb.AppendFormat( " \\u{0} " , Convert.ToString(( int )c, 16 )); Response.Write(sb.ToString());

你可能感兴趣的:(unicode字符)