本文实例讲述了C#基于正则去掉注释的方法。分享给大家供大家参考,具体如下:
string HoverTreeClearMark(string input)
{
input = Regex.Replace(input, @"/\*[\s\S]*?\*/", "", RegexOptions.IgnoreCase);
input = Regex.Replace(input, @"^\s*//[\s\S]*?$", "", RegexOptions.Multiline);
input = Regex.Replace(input, @"^\s*$\n", "", RegexOptions.Multiline);
input = Regex.Replace(input, @"^\s*//[\s\S]*", "", RegexOptions.Multiline);
return input;
}
本方法可以去掉 /* */ 和 //注释,以及去掉空白行
[b]PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:[/b]
[b]JavaScript正则表达式在线测试工具:
[/b][url=http://tools.jb51.net/regex/javascript]http://tools.jb51.net/regex/javascript[/url]
[b]正则表达式在线生成工具:
[/b][url=http://tools.jb51.net/regex/create_reg]http://tools.jb51.net/regex/create_reg[/url]
更多关于C#相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/344.htm]C#正则表达式用法总结[/url]》、《[url=http://www.1sucai.cn/Special/792.htm]C#编码操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/266.htm]C#中XML文件操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/165.htm]C#常见控件用法教程[/url]》、《[url=http://www.1sucai.cn/Special/125.htm]WinForm控件用法总结[/url]》、《[url=http://www.1sucai.cn/Special/116.htm]C#数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/478.htm]C#面向对象程序设计入门教程[/url]》及《[url=http://www.1sucai.cn/Special/227.htm]C#程序设计之线程使用技巧总结[/url]》
希望本文所述对大家C#程序设计有所帮助。