本文实例讲述了C#基于正则去掉注释的方法。,具体如下:
string HoverTreeClearMark(string input)
{
input = Regex.Replace(input, @"/*[sS]*?*/", "", RegexOptions.IgnoreCase);
input = Regex.Replace(input, @"^s*//[sS]*?$", "", RegexOptions.Multiline);
input = Regex.Replace(input, @"^s*$n", "", RegexOptions.Multiline);
input = Regex.Replace(input, @"^s*//[sS]*", "", RegexOptions.Multiline);
return input;
}
本方法可以去掉 /* */ 和 //注释,以及去掉空白行
希望本文所述对大家C#程序设计有所帮助。
注:相关教程知识阅读请移步到c#教程频道。










