简体   繁体   中英

How to replace emoji char to specific string from UITextView.text

A string from textview.text and may have emoji, then i want to replace emoji to some string like [smile] and send to server for save. I already have a map for text and emoji.

self.emoji =
    @{
      @"[pretty]"   : [NSString stringWithFormat:@"%C%C", 0xD83D, 0xDE0A],
      @"[smile]"   : [NSString stringWithFormat:@"%C%C", 0xD83D, 0xDE03],
      @"[angry]"   : [NSString stringWithFormat:@"%C%C", 0xD83D, 0xDE20]
    }

This map use for display emoji and text in uilabel that string get from server. Now, how could i convert string from textview.text correctly.

If your server support unicode, why don't you use emojis directly in your NSString ?

NSString *emojiString = @"This is a cat 😻";
  • oops, StackOverflow doesn't support unicode!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM