How to check if string in array of strings start with specific letter in Swift

1 Answer

0 votes
func stringStartsWithp(s: String) -> Bool {
    return s[s.startIndex] == "p"
}

var arr = ["swift", "c++", "php", "java", "python"]
  
if arr.contains(where: stringStartsWithp) {
    print("contains string starts with p")
}
   
   
   
   
/*
run:
 
contains string starts with p
  
*/

 



answered Sep 2, 2020 by avibootz
...