I want to check if a string contains at least one element in an array.
I tried this but I think it's too long. Imagine if I want all the alphabet in the if statement. I hope there is a proper way to do this.
var str = "Hello, playground."
let typeString = NSString(string: str)
if typeString.containsString("a") || typeString.containsString("e") || typeString.containsString("i") || typeString.containsString("o") || typeString.containsString("u") {
print("yes")
} else {
print("no")
}
// yes
I tried using an array but it doesn't work. It needs all of the elements in an array to have a result of "yes".
let vowels = ["a", "e", "i", "o", "u"]
if typeString.containsString("\(vowels)") {
print("yes")
} else {
print("no")
}
// no
Btw, I'm still a newbie and still learning. Hope someone can help. Thanks