Created
April 22, 2010 11:26
-
-
Save remy/375100 to your computer and use it in GitHub Desktop.
challenge: unicode to 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
/** | |
* == Can it be done? == | |
* | |
* I want to get from keyIdentifier to actual character, eg from U+0023 | |
* to \u0023 - which if dropped in a string is the # character: | |
* http://jsconsole.com/?%22\u0023%22 | |
* | |
* The problem is the starting point, and I know I can do it using an | |
* eval, but eval is evil, right? So how can I do it? | |
* | |
* Can you solve this? | |
* - @rem | |
*/ | |
var code = "U+0023"; | |
// evil - but works :-( | |
eval('"' + code.replace(/^U\+/, '\\u') + '"') | |
// http://jsconsole.com/?eval('%22'%20+%20%22U+0023%22.replace(/^U\+/,%20'\\u')%20+%20'%22') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solutions already rolled in:
http://twitter.com/timwhitlock/status/12633678691
http://twitter.com/beverloo/status/12633646752
String.fromCharCode(parseInt(code.substr(2), 16))
http://jsconsole.com/?var%20code%20=%20%22U+0029%22;%20String.fromCharCode(parseInt(code.substr(2),%2016))