Reputation: 1718
Google chrome automatically converts unicode strings in URL to something like this;
?querystring=مقالات
?querystring=%D9%85%D9%82%D8%A7%D9%84%D8%A7%D8%AA
My question is how to decode the encoded text in the codes for example for a comparing purpose?
if (Request.Url.Query == "?querystring=مقالات")
//do something
Upvotes: 3
Views: 7319
Reputation: 14522
Check these out :)
Console.WriteLine(System.Web.HttpUtility.UrlDecode("http://www.google.com/search?q=مقالات"));
Console.WriteLine(System.Web.HttpUtility.UrlEncode("http://www.google.com/search?q=%D9%85%D9%82%D8%A7%D9%84%D8%A7%D8%AA"));
Upvotes: 2
Reputation: 2612
URL encoding ensures that all browsers will correctly transmit text in URL strings.
Characters such as a question mark (?), ampersand (&), slash mark (/), and spaces might be truncated or corrupted by some browsers. As a result, these characters must be encoded in tags or in query strings where the strings can be re-sent by a browser in a request string.
UrlDecode
is a convenient way to access the HttpUtility.UrlDecode
method at run time from an ASP.NET application. Internally, UrlDecode
uses HttpUtility.UrlDecode
to decode strings.
The following example decodes the string named EncodedString (received in a URL) into the string named DecodedString :
String DecodedString = Server.UrlDecode(EncodedString);
Upvotes: 1