-
-
Save huobazi/3136472 to your computer and use it in GitHub Desktop.
将基于10进制的字符串unicode编码转换为基于16进制的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
// U2A('博时货'); | |
// return '\u234A\u3BaD\u42EA\u1BC3' | |
var U2A = function(s){ | |
var r = s.replace(/&#(\d+);/ig,'\\u{$1}'); | |
var A = r.match(/\d+/ig); | |
for(var i = 0;i<A.length;i++){ | |
r = r.replace('\\u{'+A[i].toString()+'}',String.fromCharCode(A[i])); | |
} | |
return r; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment