Skip to content
Advertisement

Remove last char string when string contains emojis

I’m using React Native (chat), in this app I have one emoji picker but when users press virtual backspace button emojis only remove their last unicode byte.

How can I detect if last ‘chat’ (set of unicodes) is standalone emoji unicode?

Code to split it:

JavaScript

I also tried to use Array.from(), then use slice(0,-1) and correct solutions to all cases appears when I console log it. BUT! When I set the SAME variable to the TextInput appears: 321331231221.

Some examples:

JavaScript

But if I set this last solution in my React Native TextInput component I see something like this: 312412412411 (maybe all in hex). If the value has not emojis I see the same result as well.

When I set the emoji with the emoji picker, something like ${inputValue}${newEmoji} all works out.

I do not know what to think guys :/

Advertisement

Answer

Try with slice :

JavaScript

UPDATE :

This package might help you: runes

example of your need :

JavaScript
Advertisement