How to check if a string starts with a specified substring in Swift

1 Answer

0 votes
import Foundation

let str = "Swift Programming Language";
let substr = "Swift"

if str.hasPrefix(substr) {
    print("yes")
} else {
    print("no")
}




/*
run:

yes

*/

 



answered Feb 10, 2025 by avibootz
...