c Chinese to unicode character examples to share

  • 2020-06-01 10:56:21
  • OfStack


// Other characters can be included  
public string uncode(string str) 
{ 
string outStr = ""; 
Regex reg = new Regex(@"(?i)//u([0-9a-f]{4})"); 
outStr = reg.Replace(str, delegate(Match m1) 
{ 
return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString(); 
}); 
return outStr; 
} 
// Chinese to UNICODE character  
string str = " Chinese "; 
string outStr = ""; 
if (!string.IsNullOrEmpty(str)) 
{ 
for (int i = 0; i < str.Length; i++) 
{ 
// Convert Chinese characters to 10 Base integer, and then convert to 16 Into the system unicode character  
outStr += "//u" + ((int)str[i]).ToString("x"); 
} 
} 
//UNICODE Character conversion to Chinese  
string str = "//u4e2d//u6587"; 
string outStr = ""; 
if (!string.IsNullOrEmpty(str)) 
{ 
string[] strlist = str.Replace("//","").Split('u'); 
try 
{ 
for (int i = 1; i < strlist.Length; i++) 
{ 
// will unicode String to 10 Base integer, and then convert to char Chinese characters  
outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber); 
} 
} 
catch (FormatException ex) 
{ 
outStr = ex.Message; 
} 
}


Related articles: