正则表达式,替换所有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;
} 相关推荐
wangzhaotongalex 2020-10-20
wyq 2020-11-11
TLROJE 2020-10-26
风雨断肠人 2020-10-13
duanqingfeng 2020-09-29
rechanel 2020-11-16
luofuIT成长记录 2020-09-22
phphub 2020-09-10
taomengxing 2020-09-07
MaggieRose 2020-08-19
flyingssky 2020-08-18
山水沐光 2020-08-18
jyj00 2020-08-15
AHuqihua 2020-08-09
山水沐光 2020-08-03