所以我试图找到一个正则表达式来替换所有句子中以特定单词开头的单词(在我的情况下声明)
例子 :
声明@order int
声明@order2 int
这应该可以解决问题:
var lines = new string[]
{
"declare @order int",
"test string",
"declare @order2 int"
};
string pattern = "declare";
string replacement = "something";
Regex regex = new Regex(pattern);
var output = lines.Select(l => l = (l.StartsWith(pattern)) ?
regex.Replace(l, replacement, 1) : l);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句