Results 1 to 2 of 2

Thread: Remove Emojis from QString

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    254
    Thanks
    23
    Thanked 16 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    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()

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,014
    Thanks
    280
    Thanked 816 Times in 805 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    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, 12:42
  2. Remove \n from QString
    By arturs in forum Newbie
    Replies: 4
    Last Post: 20th April 2015, 08:41
  3. QString.remove() Why not working?
    By Noob in forum Newbie
    Replies: 3
    Last Post: 6th May 2013, 18:04
  4. How to remove whitespace in qstring in beginning?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 20th August 2012, 08:16
  5. Replies: 3
    Last Post: 21st January 2011, 19:40

Tags for this Thread

Bookmarks

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.