如何使用C#从Web.Config文件中删除所有注释部分? [英] How Can I Remove All The Commented Section From The Web.Config File Using C#?

查看:265
本文介绍了如何使用C#从Web.Config文件中删除所有注释部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除所有评论的部分,即<!---->之间使用c#.Pls帮助从配置文件中获取。

I want to delete all the commented section i.e between <!----> from the config file using c#.Pls help.

推荐答案

你可以使用正则表达式:

You could do it with a Regex:
(\<!--)(.*?)-\>)



将文件读入字符串,正则表达式并将其写回:


Read your file into a string, regex it, and write it back:

string data = File.ReadAllText(path);
string noComments = Regex.Replace(data, @"(\<-)(.*?)-\>)", "");
File.WriteAlText(path, noComments);





但我不知道你为什么要删除评论:他们通常有很好的理由...-->



But I have no idea why you would want to remove comments: they are generally there for a very good reason...-->


这篇关于如何使用C#从Web.Config文件中删除所有注释部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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