Domanda

How would I change a url from % to %25 for a URL? I know I could use .Replace("%", "%25"), but what my real goal would be is to make all the conversions found HERE take place. Is there a built in function to do this or will I need to do a loop for ALL of the encoding here? I thought I was onto something with this code:

string link = System.Net.WebUtility.HtmlEncode("https://www.somegenericsite.com?something=%");

... but it returned the exact same link, not the encoded one. Any help or a nudge in the right direction would be much appreciated. Thanks!

È stato utile?

Soluzione

Try HttpUtility.UrlEncode():

HttpUtility.UrlEncode("https://www.somegenericsite.com?something=%")

This will result in

https%3a%2f%2fwww.somegenericsite.com%3fsomething%3d%25
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top