Is there any function that converts an escaped Url string to its unescaped form? System.Web.HttpUtility.UrlDecode()
can do that job but I don't want to add a reference to System.Web.dll
. Since my app is not a web application, I don't want to add a dependency for only using a function in an assembly.
UPDATE: Check Rick Strahl's blog post about the same issue.
WebUtility.UrlDecode(String) Method (System.Net)Converts a string that has been encoded for transmission in a URL into a decoded string.
URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.
It is a usual task in web development, and this is generally done while making a GET request to the API with the query params. The query params must also be encoded in the URL string, where the server will decode this. Many browsers automatically encode and decode the URL and the response string.
EDIT: Use the static method Uri.UnescapeDataString()
to decode your URLs:
Encoded: http%3a%2f%2fwww.google.com%2fsearch%3fhl%3den%26q%3dsomething%20%2323%26btnG%3dGoogle%2bSearch%26aq%3df%26oq%3d
Decoded: http://www.google.com/search?hl=en&q=something #23&btnG=Google+Search&aq=f&oq=
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