本文實例講述了C#基于正則去掉注釋的方法。分享給大家供大家參考,具體如下:
1
2
3
4
5
6
7
8
|
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; } |
本方法可以去掉 /* */ 和 //注釋,以及去掉空白行
希望本文所述對大家C#程序設計有所幫助。