删除评论,例如“//”或“/ * * /” [英] Remove comments ex.,"//" or "/* */"

查看:86
本文介绍了删除评论,例如“//”或“/ * * /”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,任何人都可以帮助如何删除文件中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 class System.Text.StringBuilder. It is mutable, but strings are immutable, so concatenating strings repeatedly will kill good performance. After parsing strings into some fragments, you Append then one by one to the instance of StringBuilder. To go back from StringBuilder to string, simply use ToString().

—SA


这篇关于删除评论,例如“//”或“/ * * /”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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