Results 1 to 2 of 2

Thread: Remove Emojis from QString

  1. #1
    Join Date
    Mar 2010
    Heredia, Costa Rica
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows

    Default Remove Emojis from QString

    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()


  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 854 Times in 841 Posts
    Qt products

    Default Re: Remove Emojis from QString

    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.

Similar Threads

  1. Replies: 1
    Last Post: 9th April 2020, 13:42
  2. Remove \n from QString
    By arturs in forum Newbie
    Replies: 4
    Last Post: 20th April 2015, 09:41
  3. QString.remove() Why not working?
    By Noob in forum Newbie
    Replies: 3
    Last Post: 6th May 2013, 19:04
  4. How to remove whitespace in qstring in beginning?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 20th August 2012, 09:16
  5. Replies: 3
    Last Post: 21st January 2011, 20:40

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.