为什么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/