博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 将html实体编码转换到正常字符 & #40;格式
阅读量:4680 次
发布时间:2019-06-09

本文共 696 字,大约阅读时间需要 2 分钟。

获取到html实体编码字符后,通过正则获取其中的html实体编码,再统一强制转换到正常字符;

 代码如下:

string strformat = item.value7;                //将html实体编码转换到正常字符                string regx = "(?<=(& #)).+?(?=;)";                MatchCollection matchCol = Regex.Matches(strformat, regx);                if (matchCol.Count > 0)                {                    for (int i = 0; i < matchCol.Count; i++)                    {                        int asciinum = int.Parse(matchCol[i].Value);                        char c = (char) asciinum;                        strformat = strformat.Replace(string.Format("& #{0};", asciinum), c.ToString());                    }                }

 附对换表格

 

转载于:https://www.cnblogs.com/yisheng/p/8193903.html

你可能感兴趣的文章