获取到html实体编码字符后,通过正则获取其中的html实体编码,再统一强制转换到正常字符;
代码如下:
1string strformat = item.value7; 2 //将html实体编码转换到正常字符 3 string regx = "(?<=(& #)).+?(?=;)"; 4 MatchCollection matchCol = Regex.Matches(strformat, regx); 5 if (matchCol.Count > 0) 6 { 7 for (int i = 0; i < matchCol.Count; i++) 8 { 9 int asciinum = int.Parse(matchCol[i].Value); 10 char c = (char) asciinum; 11 strformat = strformat.Replace(string.Format("& #{0};", asciinum), c.ToString()); 12 } 13 }
附对换表格
