Skip to content

Instantly share code, notes, and snippets.

@FrankFang
Last active December 14, 2015 13:59
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 FrankFang/5097463 to your computer and use it in GitHub Desktop.
Save FrankFang/5097463 to your computer and use it in GitHub Desktop.
汉字变Unicode
function c2u(c){
var number = c.charCodeAt(0).toString(16);
console.log(number)
var padding = '0000';
return '\\u'+padding.slice(0,4-number.length)+number;
}
function s2u(s){
var len = s.length,result='';
for (var i =0; i< len; i++){
result+=c2u(s[i]);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment