[英]Add two Replace on the same Regex at the same time - Do two different things
我的問題是,例如,當我添加一個更像是需要替換的點時。 然后它出現了這個錯誤:
無法從字符串轉換為 System.stringComparison
如果我因此評論最后一次替換。 然后就沒有問題了,但這只有在我在 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!!!");
我也嘗試過這樣做:
如果只有Regex.Replace
返回Regex
我們將能夠鏈接Replace
: Replace(...).Replace(...).Replace(...)
; 可惜! Replace
返回string
因此我們不能對其使用Regex
方法( string
)。 選項是:
嵌套調用:
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!!!");
順序調用:
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.