I have a collection of strings within a checkListBox and I convert this collection into a List<string>
. During this conversion I can only imagine the strings are escaped due to them being in the below format:
<category title="FOO">
This then becomes
"<category title=\"FOO\">
I need to unescape these strings for comparison, and I've tried something like
s.Replace(@"\""", @""""); <-------- trying to replace all \" with "
Is this even possible? And if so what's the correct way of removing slashes from quotes in a string?
You can use Unescape
var str = "<category title=\"FOO\">";
var result = System.Text.RegularExpressions.Regex.Unescape(str);
Console.WriteLine(result); //<category title="FOO">
Console.ReadLine();
You can use Regex.Unescape Method to resolve. https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.unescape(v=vs.110).aspx
Or you can use Uri.UnescapeDataString Method.
https://msdn.microsoft.com/en-in/library/system.uri.unescapedatastring(v=vs.110).aspx
Try Replace("\\"", "\""), or even better Replace("\", "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With