c# - convert unicode(hex) to string in C#
问题描述
Is there any approach to convert Unicode like "U+4E0B" to its equivalent character?
Ex- {\U+FF8D\U+FF9E\U+FF9D\U+FF84\U+FF9E\U+FF97\U+FF72\U+FF9D - \U+4E0B}
any type of help is appreciated!
解决方案
简单的方法是使用Regex.Replace()
带有委托的正则表达式 +:
string str = @"\U+FF8D\U+FF9E\U+FF9D\U+FF84\U+FF9E\U+FF97\U+FF72\U+FF9D - \U+4E0BFooBar";
var rx = new Regex(@"\\U\+([0-9A-F]{4})");
string str2 = rx.Replace(str, m =>
{
ushort u = Convert.ToUInt16(m.Groups[1].Value, 16);
return ((char)u).ToString();
});
不清楚是否要不区分大小写(因此\u+ff9e
有效),然后使用:
var rx = new Regex(@"\\[Uu]\+([0-9A-Fa-f]{4})");
推荐阅读
- reactjs - Reactjs-ffsevents 不是函数
- sql - 了解 SQL Server Int 数据类型
- magento2 - nginx config Magento 2.4 - 未加载css js
- sql - 加入对多个列出的外 ID 键表的查询?
- python - Python PIL ValueError:没有足够的图像数据
- file - 列出子文件夹中的前几个文件,并使用 VBScript 返回包含文件名和文件夹名的列表
- matlab - 斐波那契递归值跟踪器
- r - Сustomize R 在子图中绘制颜色
- c# - 如何创建预制件并指定下降率
- java - 我可以在不使用静态变量或方法的情况下在两个 JFrame 之间进行通信吗?