gpt4 book ai didi

c# - 从源文件中删除所有注释(单行/多行)和空行

转载 作者:可可西里 更新时间:2023-11-01 08:25:10 24 4
gpt4 key购买 nike

<分区>

如何从 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

我们可以拥有比上述三个示例复杂得多的来源。有人可以建议正则表达式模式或其他方法来解决这个问题。我已经在互联网上浏览了很多东西,但找不到任何有用的东西。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com