[英]Add two Replace on the same Regex at the same time - Do two different things
My problem is that when I for example add a point more like it needs replacing.我的问题是,例如,当我添加一个更像是需要替换的点时。 Then it comes up with this error:
然后它出现了这个错误:
cannot convert from string to System.stringComparison
无法从字符串转换为 System.stringComparison
If I thus comment on the last replace.如果我因此评论最后一次替换。 Then there are no problems but this only happens if I have added the extra replace on my Regex.
然后就没有问题了,但这只有在我在 Regex 上添加了额外的替换时才会发生。
text = Regex.Replace(text, @"{(?s)(.*){medlem}}.*{{medlemstop}}",
"<img src=\"https://aaaa.azureedge.net/imagesfiles/hello.png\" class=\"img-responsive\" alt=\"hello world\">")
.Replace(text, @"{(?s)(.*){pay}}.*{{paystop}}", "ERROR HERE!!!");
I have also tried to do this:我也尝试过这样做:
https://stackoverflow.com/a/6276014/12596984 https://stackoverflow.com/a/6276014/12596984
if only Regex.Replace
returns Regex
we'll be able to chain Replace
: Replace(...).Replace(...).Replace(...)
;如果只有
Regex.Replace
返回Regex
我们将能够链接Replace
: Replace(...).Replace(...).Replace(...)
; but alas!可惜! the
Replace
returns string
so we can't use Regex
methods on it ( string
). Replace
返回string
因此我们不能对其使用Regex
方法( string
)。 The options are:选项是:
Nested calls:嵌套调用:
text = Regex.Replace(
Regex.Replace(
text,
@"{(?s)(.*){medlem}}.*{{medlemstop}}",
"<img src=\"https://aaaa.azureedge.net/imagesfiles/hello.png\" class=\"img-responsive\" alt=\"hello world\">"),
@"{(?s)(.*){pay}}.*{{paystop}}",
"ERROR HERE!!!");
Sequential calls:顺序调用:
text = Regex.Replace(
text,
@"{(?s)(.*){medlem}}.*{{medlemstop}}",
"<img src=\"https://aaaa.azureedge.net/imagesfiles/hello.png\" class=\"img-responsive\" alt=\"hello world\">");
text = Regex.Replace(
text,
@"{(?s)(.*){pay}}.*{{paystop}}",
"ERROR HERE!!!");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.