正则表达式替换文本文件中的未知值-C#和ASP.NET [英] Regular Expression to replace unknown value in text file - c# and asp.net
问题描述
我想使用asp.net中的c#函数替换文本文件中的一行.该行是:
I'd like to replace a line in a text file using a c# function in asp.net. The line is:
SQL-SERVER-VERSION =某个未知值"
SQL-SERVER-VERSION="some unknown value"
我不知道=之后的值可能是多少,所以我需要为此使用通配符.我希望新行显示为:
I don't know what the value after = might be so I need to use a wildcard for this. I want the new line to read:
SQL-SERVER-VERSION ="2008"
SQL-SERVER-VERSION="2008"
我正在尝试使用Regex.Replace,但是无论我尝试使用什么正则表达式,它都行不通.有人可以帮忙吗?谢谢,约翰
I'm trying to use Regex.Replace but no matter what regular expression I try, it doesn't work. Can anybody help? Thanks, John
推荐答案
我不知道您已经尝试过什么,所以无法告诉您您做错了什么,但是以下方法应该可以工作:
I don't know what you already tried so I can't tell you what you were doing wrong, but the following should work:
string s = "SQL-SERVER-VERSION=\"some unknown value\"";
s = Regex.Replace(s, "SQL\\-SERVER\\-VERSION=\".*\"", "SQL-SERVER-VERSION=\"2008\"");
这篇关于正则表达式替换文本文件中的未知值-C#和ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!