Unescape JavaScript's escape() using C#

后端 未结 7 1727
不思量自难忘°
不思量自难忘° 2020-12-08 06:29

Are the any functions in C# that handle escape/unescape like JavaScript?

I have a JSON string like this:

{\"Feeds\":[{\"Url\":\"www.test.com\",\"FeedTy

7条回答
  •  -上瘾入骨i
    2020-12-08 06:58

    To unescape without having to reference System.Web in order to use HttpUtility, try this:

    Str = Str.Replace("+", " ");
    Str = Regex.Replace(Str, "%([A-Fa-f\\d]{2})", a => "" + Convert.ToChar(Convert.ToInt32(a.Groups[1].Value, 16)));
    

    Also, when I tried HttpUtility.UrlDecode, it didn't work for special characters áéíóúñ.

提交回复
热议问题