有没有办法确定字符串不包含 if 语句中的某些内容?基本上与 .contains 相反。
包含示例:
if someItem.contains(x) {
code
}
我正在寻找的示例:
if someItem.doesNotContain(x) {
code
}
我正在寻找 doesNotContain 的解决方案。
非常感谢任何帮助,谢谢。
*仅供引用,我是 Swift 和编程的新手,谢谢您的评论。
最佳答案
不,Apple 不提供任何类似 doesNotContain
或类似功能的功能。
但是如果您不想添加 else
部分,那么您可以简单地使用:
if !someItem.contains("hello") {
//This means your someItem doesn't contain "hello" string.
}
关于swift - Xcode Swift - 有与 .contains 相反的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54760102/