C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Here: All 3 of the if-statement conditions evaluate to true. The inner 3 print statements are reached.
Swift program that uses hasPrefix, hasSuffix
var test = "one and two"
// Test the string's prefix.
if test.hasPrefix("one") {
print(true)
}
// Test the suffix.
if test.hasSuffix("two") {
print(true)
}
// This prefix is not correct.
// ... Use exclamation mark to test for this condition.
if !test.hasPrefix("abc") {
print(false)
}
Output
true
true
false