0
[SOLVED] Escaping emojis in javascript
How to escape emoji characters in javascript? Eg: 😝 => 😝 😞 => 😞 But my code makes 2 characters, 😝 => �� Which is invalid code? What is the correct way. Any ideas? https://code.sololearn.com/WtVy7RukBe2h/?ref=app
6 Réponses
+ 2
It ignores the newline because of your regex pattern. Dot (.) does not match newlines. Here is a fixed version (see line 5)
https://code.sololearn.com/W2ej6jz9ngia/?ref=app
+ 1
This will hopefully help (sorry if it doesn't because I haven't read the full article)
https://medium.com/reactnative/emojis-in-javascript-f693d0eb79fb
+ 1
March Zucherberg apparently, "😝".codePointAt(0) returns 128541. So the example you mentioned in the question is actually the code point at position 0. And it can be easily converted to the emoji.
Using String.fromCodePoint() on the hex equivalent of the code point at position 0 of the emoji returns the emoji itself. See if this helps
https://code.sololearn.com/Wuah65dHU7pO/?ref=app
+ 1
After some research on your code and more on the post you provided a link on your code, I finally got what I needed.
But still unknown if this method is still efficient.
Please have a look at it..
https://code.sololearn.com/WV3mUti1hj39/?ref=app
+ 1
But I found 1 problem in it i.e. it doesn't escape newlines to =>
Totally ignores it.
0
XXX thanks, but I didn't understand anything, full of regex.
So, I did some more research and found another way,
It gives the correct emoji character code but also one more code at the end.
https://code.sololearn.com/W5c3br0qEyQJ/?ref=app
8...; These codes.