由emojis

时间:2017-10-12 18:08:41

标签: ios arrays iphone swift swift3

我会按照正确的顺序在表情符号和句子数组中拆分一个字符串。

更新

免费使用其他功能,我已尝试过" split"但不是强制性的。

完成更新

  

示例:" pippo sta pippando" - > ["&#34 ;,   " pippo sta pippando",""]

我已尝试过的内容:

let str = "‍‍‍ pippo sta pippando "
print(Array(str))
  

// [""," "," p","我"," p"," p"," o", " "," s"," t"," a",   ""," p","我"," p"," p"," a& #34;," n"," d"," o"," ",""]

let arrTot = str.split(whereSeparator: { $0 == " "})
print(arrTot)
  

// [""," pippo"," sta"," pippando","" ]

for p in arrTot {
    print(String(p).containsEmoji)
}
  

/ *真        假        假        假        真正        * /   所以containsEmoji正在工作

但是当我想要使用split时:

print(str.split(whereSeparator: {$0.containsEmoji })) 
  

// [" pippo sta pippando"]

正在过滤而不是分裂

  

我想要的 - >我希望的输出:[""," pippo sta pippando",""]

有什么想法吗?

EXTENSION:

extension UnicodeScalar {
    var isEmoji: Bool {

        switch value {
        case 0x1F600...0x1F64F, // Emoticons
        0x1F300...0x1F5FF, // Misc Symbols and Pictographs
        0x1F680...0x1F6FF, // Transport and Map
        0x2600...0x26FF,   // Misc symbols
        0x2700...0x27BF,   // Dingbats
        0xFE00...0xFE0F,   // Variation Selectors
        0x1F900...0x1F9FF,  // Supplemental Symbols and Pictographs
        65024...65039, // Variation selector
        8400...8447: // Combining Diacritical Marks for Symbols
            return true

        default: return false
        }
    }

    var isZeroWidthJoiner: Bool {
        return value == 8205
    }
}
extension String {
    var containsEmoji: Bool {
        return unicodeScalars.contains { $0.isEmoji }
    }
}
extension Character {
    var containsEmoji: Bool {
        return unicodeScalars.contains { $0.isEmoji }
    }
}

0 个答案:

没有答案