获取字符串中的表情符号计数

问题描述:

我想查找用户输入到EditText中的表情符号数量.如果用户仅输入表情符号,并且使用3个或更少,我希望能够在应用程序中以更大的字体显示该字符串.

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 string within the app with a larger font.

现在我确实碰到了这篇文章,它确实有助于检测字符串中是否存在表情符号,但是我还无法弄清楚如何计算表情符号的数量.

Right now I did come across this post which does help detect if emojis are present in the string, but I have not been able to figure out how to count the number of emojis.

检测字符是否在字符串是表情符号(使用Android)

有人知道我如何从字符串中获取表情符号计数吗?

Does anyone know how I can get the emoji count from a String?

    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;