Skip to content

Instantly share code, notes, and snippets.

@myaumyau
Created February 18, 2013 03:55
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myaumyau/4975024 to your computer and use it in GitHub Desktop.
Save myaumyau/4975024 to your computer and use it in GitHub Desktop.
[js]数値文字参照(16進数, 10進数)を文字列に変換
function hexNumRefToString(hexNumRef) {
return hexNumRef.replace(/&#x([0-9a-f]+);/ig, function(match, $1, idx, all) {
return String.fromCharCode('0x' + $1);
});
}
function decNumRefToString(decNumRef) {
return decNumRef.replace(/&#(\d+);/ig, function(match, $1, idx, all) {
return String.fromCharCode($1);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment