Is there a way to determine if string does not contain something in an if statement? Basically the opposite of .contains .
Example of contains:
if someItem.contains(x) {
code
}
Example of what I am looking for:
if someItem.doesNotContain(x) {
code
}
Where a slolution for doesNotContain is what I am looking for.
Any help is greatly appreciated, thank you.
*FYI, I am new to Swift and to programming, thank you for your comments.
No Apple doesn't provide any function like doesNotContain or something similar.
But if you don't want to add else part then you can simply use:
if !someItem.contains("hello") {
//This means your someItem doesn't contain "hello" string.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With