删除评论,例如“//”或“/ * * /” [英] Remove comments ex.,"//" or "/* */"
本文介绍了删除评论,例如“//”或“/ * * /”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,任何人都可以帮助如何删除文件中c#中的注释引用
例如:在文件中
//包括studio.c
/ *这是示例* /
/ *
这是第二个例子
* /
输出应该是:
包括studio.c
这是示例
这是第二个示例
i尝试使用Remove(),IndexOf(),Replace()。但是没有得到,提前谢谢
Hello , can any one help how to remove comments quotes in c# in a file
For Example: In a File
//include studio.c
/*This is Example*/
/*
This is second Example
*/
OUTPUT should be :
include studio.c
This is Example
This is second Example
i tried using Remove(), IndexOf(), Replace() . but not getting , thanks in advance
推荐答案
你正在尝试完全正确的事情。所有你需要把它们放在一起。 :-)
另一个想法:出于性能考虑,使用类System.Text.StringBuilder
更好。它是可变的,但是字符串是不可变的,因此重复连接字符串将会破坏良好的性能。在将字符串解析为某些片段后,您追加
然后逐个添加到StringBuilder
的实例。要从StringBuilder
返回到字符串,只需使用ToString()
。
-SA
You are trying perfectly right things. All you need it to put them together. :-)
Another idea: for performance sake, its much better to use the classSystem.Text.StringBuilder
. It is mutable, but strings are immutable, so concatenating strings repeatedly will kill good performance. After parsing strings into some fragments, youAppend
then one by one to the instance ofStringBuilder
. To go back fromStringBuilder
to string, simply useToString()
.
—SA
这篇关于删除评论,例如“//”或“/ * * /”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文