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

Cid
  • 14,968
  • 4
  • 30
  • 45

1 Answers1

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!!!");
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215