I have a QString with emojis of different kinds.
Is there a way to remove any emojis from a QString?
I can use replace() for some cases but since I don't know which emoji I will have then I would need a general replace()
Thanks
I have a QString with emojis of different kinds.
Is there a way to remove any emojis from a QString?
I can use replace() for some cases but since I don't know which emoji I will have then I would need a general replace()
Thanks
From what I read online, all emojis are represented in UTF-8 encoding as a string of 8 bytes, the first six of which are 0xF09F98 or 0xF09F99 followed by two more bytes for the specific emoji. See this table.
You can see that the table includes ton of things in addition to the standard "smiley" emojis. It looks like most of them begin with the 4-byte string 0xF09F.
So I assume you would convert your QString into the UTF-8 representation (using QString::toUtf8()) and then scan the resulting QByteArray in 8-byte chunks for the 0xF09F signature as the first 4 bytes of each chunk, and then remove those 8 bytes (e.g. by creating a QByteArray copy as you go along, adding the acceptable characters and ignoring the emojis). Finally, you convert the QByteArray back into a QString using QString::fromUtf8().
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks