我如何使用类似的东西
return Regex.Replace("/(^)?(<br\s*\/?>\s*)+$/", "", source);
替换这种情况:
<br>thestringIwant => thestringIwant
<br><br>thestringIwant => thestringIwant
<br>thestringIwant<br> => thestringIwant
<br><br>thestringIwant<br><br> => thestringIwant
thestringIwant<br><br> => thestringIwant
它可以在开头或结尾有多个br标签,但是我不想在中间删除任何br标签。
几个循环可以解决该问题,并且更易于阅读和理解(使用正则表达式=明天您将查看自己的代码,以了解到底发生了什么)
while(source.StartsWith("<br>"))
source = source.SubString(4);
while(source.EndsWith("<br>"))
source = source.SubString(0,source.Length - 4);
return source;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句