AdmiralCat3
AdmiralCat3

Reputation: 99

Convert string to URL in c#

It definitely has been asked many times, but offered solutions does not seem to work.

Input:

sample text

Output:

sample%20text

I'm using suggested HttpUtility.UrlEncode() but instead of desired output it returns:

sample+text

Am i doing something wrong, or this method is no longer valid?

Upvotes: 1

Views: 13566

Answers (1)

kumi95
kumi95

Reputation: 91

Try this:

string str = "sample text";
string url = Uri.EscapeDataString(str);

Upvotes: 5

Related Questions