从源文件中删除所有注释(单行/多行)空行(&) [英] Remove all comment (single-/multi-line) & blank lines from source file

查看:156
本文介绍了从源文件中删除所有注释(单行/多行)空行(&)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从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。 之后,删除空行就很简单了。

这篇关于从源文件中删除所有注释(单行/多行)空行(&)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆