正则替换html标签我自己写了一个正则表达式,<(.|/n)+?> 这个是替换所以HTML标签,非贪婪的,多行的。 如果我想替换得到所以非HTML标签, 我的代码就只能是这样,先找打HTML标签,然后将标签替换掉。 能不能直接找到非HTML标签呢。。 还有个问题就是,,截取字符串的长度。 我下面的这种方法,没有判断中文或者非中文,截取的长度总是有长有短。 不知道有没有好点的办法让截取的长度,一样长的,而不是str.Length的长度。
public static string formatString(string str, int size) { string temp = str; Regex regex = new Regex("<.+?>"); temp = regex.Replace(str, ""); temp = temp.Replace("/r/n", ""); temp = temp.Replace(" ", ""); if (temp.Length >= size) { temp = temp.Substring(0, size - 3) + " "; } return temp; } 以上这篇正则表达式,替换所有HTML标签的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持wanshiok.com。 正则替换html标签
|