0

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

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.

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

2
  • Regex.Replace() returns a string. You can't do Regex.Replace().Replace() and use Regex Commented Dec 27, 2019 at 10:06
  • 3
    text = Regex.Replace(Regex.Replace(source, pattern, value), anotherPattern, anotherValue); Commented Dec 27, 2019 at 10:07

1 Answer 1

1

if only Regex.Replace returns Regex we'll be able to chain Replace: Replace(...).Replace(...).Replace(...); but alas! the Replace returns string so we can't use Regex methods on it (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!!!");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for u Answer! i will try to make this simple for mig :) Good day to u!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.