How to get the index of a character in a string with Swift

1 Answer

0 votes
var s = "swift java python"
if let i = s.firstIndex(of: "a") {
   print(i.utf16Offset(in:s)) 
} else {
   print("not found")
}



 
/*
run:
 
7
 
*/

 



answered Jun 4, 2021 by avibootz

Related questions

...