使用string.Replace在C#中转义字符串? [英] Unescaping strings in c# using string.Replace?
本文介绍了使用string.Replace在C#中转义字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在checkListBox中有一个字符串集合,并将此集合转换为 List< string>
。在此转换过程中,我只能想象到字符串由于采用以下格式而被转义了:
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">
然后变成
"<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?
推荐答案
您可以使用 Unescape
var str = "<category title=\"FOO\">";
var result = System.Text.RegularExpressions.Regex.Unescape(str);
Console.WriteLine(result); //<category title="FOO">
Console.ReadLine();
这篇关于使用string.Replace在C#中转义字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文