Skip to content

Instantly share code, notes, and snippets.

@kkozmic
Created September 24, 2011 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkozmic/1238786 to your computer and use it in GitHub Desktop.
Save kkozmic/1238786 to your computer and use it in GitHub Desktop.
say I want to escape C# string: @"http://somesite.com/?arg=value&foo=bar"
HtmlEncode does:
http://somesite.com/?arg=value&foo=bar
JavaScript escape is:
http:\x2F\x2Fsomesite.com\x2F?arg=value\&foo=bar
@hazzik
Copy link

hazzik commented Sep 24, 2011

javascript -> c#

escape -> have no c# analogue?

encodeURI -> Uri.EscapeUriString

encodeURIComponent -> HttpUtility.UrlEncode or Uri.EscapeDataString

According to http://xkr.us/articles/javascript/encode-compare/
you should avoid use of escape() whenever possible. The best alternative is usually encodeURIComponent()

Also note that HttpUtility.HtmlEncode encodes html-entities & -> &, > -> > and other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment