Get Emoji Count In String

前端 未结 5 1785
暗喜
暗喜 2021-01-15 17:01

I would like to find how many emojis the user has input into an EditText. If the user only enters emojis, and uses 3 or less, I want to be able to display that

5条回答
  •  [愿得一人]
    2021-01-15 17:24

        int emojiCount = 0;
    
        for (int i = 0; i < yourString.length(); i++) {
         int type = Character.getType(yourString.charAt(i));
          if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
           emojiCount++;
          }
        }
    
    return emojiCount/2;
    

提交回复
热议问题