如何从 C# 源文件中删除所有注释和空行。请记住,可能存在嵌套注释。一些例子:
string text = @"//not a comment"; // a comment
/* multiline
comment */ string newText = "/*not a comment*/"; // a comment
/* multiline // not a comment
/* comment */ string anotherText = "/* not a comment */ // some text here\"// not a comment"; // a comment
我们可以拥有比上面三个例子更复杂的源。
有人可以建议一种正则表达式模式或其他方法来解决这个问题吗?我已经在互联网上浏览了很多东西,但找不到任何有用的东西。
要删除评论,请参阅这个答案 https://stackoverflow.com/a/3524689/1158522。
之后,删除空行就很简单了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)