1

I have a string below, need to convert it to URl in class file, it contains special characters.

"http://www.GenerateURL.com/try?origins=**Rue 66 & Rue Oued Draa / Rue 77, Tangier, Morocco**&destinations=**Boulevard Lalla Asmaa, Casablanca, Morocco**&language=en-EN&sensor=false"

Many Thanks

leppie
  • 115,091
  • 17
  • 196
  • 297
DeepakJ
  • 378
  • 4
  • 14

3 Answers3

1

You can use HttpUtility.UrlEncode(). Here is the documentation: http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx

Daniel Gabriel
  • 3,939
  • 2
  • 26
  • 37
0

You need to use System.Web.HttpUtility.UrlEncode for this:

string encodedString ="http://www.GenerateURL.com/try?origins=**Rue 66 & Rue Oued Draa / Rue 77, Tangier, Morocco**&destinations=**Boulevard Lalla Asmaa, Casablanca, Morocco**&language=en-EN&sensor=false";

 string real = System.Web.HttpUtility.UrlEncode(encodedString);

Use Server.UrlEncode

You need an instance of the HttpServerUtility class, because the UrlEncode method is not static.

See http://msdn.microsoft.com/en-us/library/system.web.httpserverutility(v=VS.90).aspx

Nayeem Mansoori
  • 821
  • 1
  • 15
  • 41
0

You can use HttpServerUtility.UrlEncode

Geeky Ninja
  • 6,002
  • 8
  • 41
  • 54