.net unicode汉字互相转换解决方法
public static string ConvertToGB(string unicodeString) { string[] strArray = unicodeString.Split(new string[] { @"u" }, StringSplitOptions.None); string result = string.Empty; for (int i = 0; i < strArray.Length; i++) { if (strArray[i].Trim() == "" || strArray[i].Length < 2 || strArray.Length <= 1) { result += i == 0 ? strArray[i] : @"u" + strArray[i]; continue; } for (int j = strArray[i].Length > 4 ? 4 : strArray[i].Length; j >= 2; j--) { try { result += char.ConvertFromUtf32(Convert.ToInt32(strArray[i].Substring(0, j), 16)) + strArray[i].Substring(j); break; } catch { continue; } } } return result; } public static string ConvertToUnicode(string strGB) { char[] chs = strGB.ToCharArray(); string result = string.Empty; foreach (char c in chs) { result += @"u" + char.ConvertToUtf32(c.ToString(), 0).ToString("x"); } return result; }
平淡中储蓄成长
相关文章
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~