Created
July 16, 2013 05:06
-
-
Save Gaubee/6005934 to your computer and use it in GitHub Desktop.
汉字转unicode编码
This file contains hidden or 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 n2a(str,f){ | |
var reg = f ? /./g : /[\u4e00-\u9fa5]/g; | |
return str.replace(reg,function(a){ | |
return "\\u" + ('0000'+Number(a.charCodeAt(0)).toString(16)).slice(-4); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment