Skip to content

Instantly share code, notes, and snippets.

@jayli
Created July 13, 2012 07:04
Show Gist options
  • Save jayli/3103278 to your computer and use it in GitHub Desktop.
Save jayli/3103278 to your computer and use it in GitHub Desktop.
将基于10进制的字符串unicode编码转换为基于16进制的unicode字符串编码
// 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