ios - 查看 Swift 字符串是否包含表情符号

标签 ios swift string unicode emoji

<分区>

我在一个应用程序中工作,我需要从字符串中查找表情符号字符意味着一个字符串包含一个或多个表情符号?因为我是 swift 的新手,所以我不知道它。

例如。 “新手😀”将返回 yes 和 “新手”将返回无

最佳答案

是的,请使用以下方法识别表情符号

public var checkcontainEmoji: Bool 
{
    for ucode in unicodeScalars
    {
        switch ucode.value
        {
        case 0x3030, 0x00AE, 0x00A9,
        0x1D000...0x1F77F,
        0x2100...0x27BF,
        0xFE00...0xFE0F,
        0x1F900...0x1F9FF:
            return true
        default:
            continue
        }
    }
    return false
}

输出:- "HI 😀".checkcontainEmoji --> TRUE

关于ios - 查看 Swift 字符串是否包含表情符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47954461/

相关文章:

swift - OS X App Review Team 的空白屏幕;为其他人工作

iphone - 使用 MPMoviePlayerController 播放视频,同时使用 AudioQueue 进行录制

ios - 无法从 ios 中的当前 View Controller 调用导航 Controller

ios - 如何让 UI TableView 在屏幕外启动?

ios - 将 UITableViewCell 类中的选择器添加到 UITableViewController 类

ios - 你能在本地快速保存一组 ViewControllers (NSKeyedArchiver) 吗?

ios - 将手势识别器放在 View 或 Controller 类中

c - 在 C 中处理后获取字符串并返回相同的函数

R:我的数据框有 2 列,每行都有一串数字,有没有办法拆分字符串并添加每列的值?

c++ - 为什么 c++ string1.size() minus string2.size() 得到错误的答案?