Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to Javascript's encodeURI? [duplicate]

C#'s equivalent to encodeURIComponent is well-covered on SO and elsewhere, but what about encodeURI? Basically I want to encode invalid URL characters only and not reserved characters such as /, :, etc. So

"http://www.example.com/my cool page"

would be encoded to

"http://www.example.com/my%20cool%20page"

Is there something baked into .NET to do this? Or is a regex my best bet?

like image 839
Todd Menier Avatar asked Sep 21 '25 11:09

Todd Menier


1 Answers

Try

Uri.EscapeUriString("http://www.mysite.com/my cool page")
like image 186
JaredPar Avatar answered Sep 23 '25 01:09

JaredPar