Search code examples
c#.netstringurldecodestring-decoding

Decoding strings in c#


I have an app that works with some texts and I need to decode strings like:

example\x27s string

example\u0027s string

For the first one I tried using Uri.UnescapeDataString(string.Replace("\\x", "%")) which works but not always because if the string is something like "the 40% of somethings's stuff", it throws an Exception because of the "40%".

For the second one I don't really know how to decode that.

Is there something I can use to decode those two kind of strings?


Solution

  • Try:

    System.Web.HttpUtility.UrlDecode(input);
    

    Results:

    "example\x27s string" -> "example's string"
    "example\u0027s string" -> "example's string"
    

    See MSDN.