获取字符串中的表情符号计数 [英] Get Emoji Count In String

查看:202
本文介绍了获取字符串中的表情符号计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查找用户输入到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;

这篇关于获取字符串中的表情符号计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆