Swift 字符集减法

标签 swift

为什么characters1不为空?

var characters1 = CharacterSet.decimalDigits
let characters2 = CharacterSet(charactersIn: "01234567890")
characters1.subtract(characters2)
print(characters1.isEmpty)

这里一切正常

var characters1 = CharacterSet(charactersIn: "9876543210")
let characters2 = CharacterSet(charactersIn: "0123456789")
characters1.subtract(characters2)
print(characters1.isEmpty)

最佳答案

来自docs (强调我的)

Informally, this set is the set of all characters used to represent the decimal values 0 through 9. These characters include, for example, the decimal digits of the Indic scripts and Arabic.

因此,CharacterSet.decimalDigits 不仅包含“9876543210”,它们还包含来自印度文字(和其他文字)的数字。

关于Swift 字符集减法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52276160/

相关文章:

swift - 内部子类化 UITableViewCell 重写 Func LayoutSubviews 被称为 Double

ios - 如何用 "Today at xx:xx pm", "Yesterday at xx:xx am"之类的人类语言显示日期?

ios - 使用 Firebase 数据在 TableViewCell 中实现共享按钮

ios - 推送通知操作未在 Swift 中显示?

ios - 出现错误时重新发送本地通知

ios - NSManagedObject 子类实现具有所需 init 的协议(protocol)的 Swift 链接器错误

ios - 在不将屏幕截图上传到 iTunes Connect 的情况下测试应用内购买

xcode - NS任务 : Couldn't posix_spawn: error 13 when launching app

ios - 在 Xcode 7.2 beta 之后,项目无法在 7.1 上运行

Swift BinaryFloatingPoint 泛型在 log10() 调用上暴露编译错误