Last active
December 14, 2015 13:59
-
-
Save FrankFang/5097463 to your computer and use it in GitHub Desktop.
汉字变Unicode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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