anthonypliu
anthonypliu

Reputation: 12437

How to encode a URL string

I have a string that contains a url which looks like this:

http://www.test.com/images/tony's pics.jpg

I need the url to look like this:

http://www.test.com/images/tony%27s%20pics.jpg

How would I programmatically solve this with a url in a STRING form. Thanks.

Upvotes: 2

Views: 3507

Answers (2)

ptfaulkner
ptfaulkner

Reputation: 712

I would think this would easily be solved by using the HttpUtility UrlEncode:

string url = "http://www.test.com/images/" + HttpUtility.UrlEncode("tony's pics.jpg");

Upvotes: 9

Mike Dinescu
Mike Dinescu

Reputation: 55760

Have a look at UrlEncode of the HttpServerUtility:

HttpServerUtility.UrlEncode("http://www.test.com/images/tony's pics.jpg");

Upvotes: 0

Related Questions