Skip to content

Instantly share code, notes, and snippets.

@xxami
Last active August 29, 2015 14:14
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 xxami/f5bc98f81b0949e942f8 to your computer and use it in GitHub Desktop.
Save xxami/f5bc98f81b0949e942f8 to your computer and use it in GitHub Desktop.
javascript encode utf-8

##encode

console.log(unescape(encodeURIComponent("string to be encoded")));

##with escape formatting

console.log(encodeURIComponent("string to be encoded").replace(/%.{2}/g, function(v) { return "\\x" + v.substring(1, 3).toLowerCase(); }));

this will be displayed, formatted with \x for use as escape sequences in various languages

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