//Unicode 转中文 private void button1_Click(object sender, EventArgs e) { string unicode = @"U5fae"; string result = string.Empty; string[] strlist = unicode.Replace("\", "").Split('U'); string s = strlist[1]; result = ((char)int.Parse(s, System.Globalization.NumberStyles.HexNumber)).ToString(); MessageBox.Show(result); } private void button2_Click(object sender, EventArgs e) { string path = @"E:expexp.txt"; string content = File.ReadAllText(path); string[] array = content.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); StringBuilder sb = new StringBuilder(); foreach (var item in array) { string[] temp = item.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); sb.Append(temp[0]); sb.Append("="); sb.Append("["); string str = temp[1].Trim().Trim('"','[',']'); if (Regex.IsMatch(str, @"^[A-Z]{2}$")) { sb.Append(str); } else { string[] strlist = str.Replace("\", "").Split(new char[] { 'U' }, StringSplitOptions.RemoveEmptyEntries); string result = string.Empty; foreach (var s in strlist) { result += ((char)int.Parse(s, System.Globalization.NumberStyles.HexNumber)).ToString(); } sb.Append(result); } sb.Append("]"); sb.Append(" "); } File.WriteAllText(@"E:expdemo.txt", sb.ToString()); MessageBox.Show("转换成功"); }
上图 转为 下图