Skip to content

Instantly share code, notes, and snippets.

View lzl124631x's full-sized avatar
💻
Learning

Richard Liu lzl124631x

💻
Learning
View GitHub Profile
String.prototype.toUnicode = function(){
var result = "";
for(var i = 0; i < this.length; i++){
result += "\\u" + ("000" + this[i].charCodeAt(0).toString(16)).substr(-4);
}
return result;
};
"みどりいろ".toUnicode(); //"\u307f\u3069\u308a\u3044\u308d"
"Mi Do Ri I Ro".toUnicode(); //"\u004d\u0069\u0020\u0044\u006f\u0020\u0052\u0069\u0020\u0049\u0020\u0052\u006f"