Loading ...

Regex: Can not access non-static method Replace in static context | CodeAsp.Net

Regex: Can not access non-static method Replace in static context

 /5
0 (0votes)

I encountered a piece of code where regex replacement was done in the following way:

Regex.Replace(@"\d+", m => new string(m.Value.Reverse().ToArray()));

It was giving the following error: Can not access non-static method Replace in static context

The issue with the above code was that the inputstring parameter was missing. The oslution was to pass the input string param:

Regex.Replace(inputString,@"\d+", m => new string(m.Value.Reverse().ToArray()))

Comments (no comments yet)

Top Posts