Reputation: 126357
How do I check if a String
includes a specific Character
?
For example:
if !emailString.hasCharacter("@") {
println("Email must contain at sign.")
}
Upvotes: 3
Views: 2508
Reputation: 6775
You can use this
if emailString.rangeOfString("@") == nil {
println("Email must contain at sign.")
}
Upvotes: 0
Reputation: 726599
You can use the free-standing find
function, like this:
let s = "hello"
if (find(s, "x") != nil) {
println("Found X")
}
if (find(s, "l") != nil) {
println("Found L")
}
Upvotes: 4
Reputation: 21137
Here you go:
if emailString.rangeOfString("@") != nil{
println("@ exists")
}
Upvotes: 0