[英]Global find and replace in C#
I have a string in C# that will looks something like this: 我在C#中有一个字符串,看起来像这样:
GET TEXT'somethign' OR TEXT'another' ...
Everytime there is a TEXT'...'
, I want to remove the wrapping TEXT'...'
so that just the value remains. 每当有一个
TEXT'...'
,我都希望删除包装的TEXT'...'
以便仅保留该值。 In other words, if I passed in the string above, the result would be: 换句话说,如果我传入上面的字符串,结果将是:
GET somethign OR another
I'm not sure how to remove the wrappers. 我不确定如何删除包装纸。 To the best of my knowledge, the String.Replace function does not support templates.
据我所知,String.Replace函数不支持模板。 For that reason, I feel kind lost in the approach I should take.
因此,我对应该采取的方法感到迷茫。
string.Replace
isn't best suited for this, what you need is a Regex.Replace
. string.Replace
不是最适合此功能的,您需要的是Regex.Replace
。
var input = "GET TEXT'somethign' OR TEXT'another' ...";
var output = Regex.Replace(input, "TEXT'([^']+)'", "$1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.