Reputation: 6294
I have a Unicode character that works with a very specific font.
I need to take that character's code, add 8, and convert it back to a string.
Here's python code that works:
char = ""
char == chr(ord(char)) # True
However, in Javascript, using the matching functions, it does not convert back correctly:
const char = "";
char == String.fromCharCode("".charCodeAt(0)) // false
Upvotes: 2
Views: 205
Reputation: 13772
When you use characters from Unicode astral planes, this is what you need:
const char = "";
console.log(char === String.fromCodePoint("".codePointAt(0)));
See also:
What every JavaScript developer should know about Unicode
JavaScript has a Unicode problem
Unicode-aware regular expressions in ES2015
ES6 Strings (and Unicode, ❤) in Depth
JavaScript for impatient programmers. Unicode – a brief introduction
Upvotes: 2