我自己写了一个正则表达式,
这个是替换所以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怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号