Created
February 12, 2012 15:30
-
-
Save dbodyas/1809069 to your computer and use it in GitHub Desktop.
JavaScript Get Unicode char as decimal
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
/* | |
Sometimes, unicode symbols that have to be inserted in an HTML page should be escaped. | |
For example, everybody know, that’s “&” should be escaped as “&”, ” ” as “ ” and so on. | |
But what, if you should insert symbol, that you never used before. So you don’t know how it should be present or escaped. | |
Code below, helps you to get valid decimal unicode for appropriate symbol. | |
*/ | |
function getCharAsDecimalUTF8(char){ | |
var getUTF8 = escape(char); | |
console.log("&#" + parseInt(getUTF8.substring(getUTF8.match(/\%u/) !== null ? 2 : 1), 16) + ";"); | |
} | |
// Ɓ † | |
getCharAsDecimalUTF8("†"); // † |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome to implement the Turkish I problem test...