Remove all comment (single-/multi-line) amp; blank lines from source file(从源文件中删除所有注释(单行/多行)空行(amp;))
问题描述
如何从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
我们可以拥有比上面三个示例复杂得多的源。 有人能建议一个正则表达式模式或其他方法来解决这个问题吗?我已经在互联网上浏览了很多东西,但找不到任何有用的东西。
推荐答案
要删除注释,请参阅this answer。 之后,删除空行就很简单了。
这篇关于从源文件中删除所有注释(单行/多行)空行(&;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!