Reputation: 1599
Python:
myString = "hello python"
if "p" in myString:
print "true"
Swift:
var myString = "is Swift really all it's cracked up to be?"
if myString.rangeOfString("c") != nil{
println("true")
}
Is this really the "swiftest" (easiest) way to check to see if a character is present in a string?
Upvotes: 0
Views: 511
Reputation: 51911
If you want to find Character
, you can use builtin contains
function:
if contains(myString, "c") {
println("true")
}
If you want to find substring, .rangeOfString("substring") != nil
is easiest.
Upvotes: 1