Search code examples
c#regex.net-coreescapingunescapestring

Unable to remove Escape sequences using Regex.Unescape in C#


I want to remove all the escape sequences from the below string which I get from Pokemon API.

"A strange seed was\nplanted on its\nback at birth.\fThe plant sprouts\nand grows with\nthis POKéMON."

I have used Regex.Unescape("A strange seed was\nplanted on its\nback at birth.\fThe plant sprouts\nand grows with\nthis POKéMON.") but I am getting the same string.

Output enter image description here

Could you please help me to sort this out?

I do not want to do a string replace as escaping sequence might be different in the next API call.


Solution

  • Of course you're getting the same string - there are no escaped characters in your example :)

    The string literal has escape characters, but those aren't present in the string itself. When the immediate window does the printout of the result, it shows it as a string literal itself. It's not the same you would get from something like Console.WriteLine, for example.