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

18th Dec 2020, 10:25 AM
Bibek Oli
Bibek Oli - avatar
6 Respostas
+ 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
19th Dec 2020, 3:17 AM
XXX
XXX - avatar
+ 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
18th Dec 2020, 10:43 AM
XXX
XXX - avatar
+ 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
18th Dec 2020, 2:11 PM
XXX
XXX - avatar
+ 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
18th Dec 2020, 3:20 PM
Bibek Oli
Bibek Oli - avatar
+ 1
But I found 1 problem in it i.e. it doesn't escape newlines to => 
 Totally ignores it.
19th Dec 2020, 2:24 AM
Bibek Oli
Bibek Oli - avatar
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 &#56...; These codes.
18th Dec 2020, 11:41 AM
Bibek Oli
Bibek Oli - avatar