I have a JSON string like {"age":"N\/A"}, now I want to replace this N/A with some static text say empty so the JSON string is converted to {"age":empty}
This is my code:
string updated = Regex.Replace(jsonstring, "(\"N\\/A\")", "empty");
Console.WriteLine(updated);
After running the code I am seeing the updated string is not modified. it is still {"age":"N\/A"}. How to fix this?
>Solution :
You have to escape characters in your regex as well, your code should look like this:
string jsonstring = "{\"age\":\"N\\/A\"}";
string updated = Regex.Replace(jsonstring, "(\"N\\\\/A\")", "empty");
Console.WriteLine(updated);