当前位置 : 主页 > 手机开发 > 其它 >

Swift CharacterSet减法

来源:互联网 收集:自由互联 发布时间:2021-06-11
为什么characters1不为空? var characters1 = CharacterSet.decimalDigitslet characters2 = CharacterSet(charactersIn: "01234567890")characters1.subtract(characters2)print(characters1.isEmpty) 一切都好 var characters1 = CharacterSet(
为什么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”,它们还包含来自印度语脚本(和其他脚本)的数字.

网友评论