How to get the first two characters from a string in Swift

1 Answer

0 votes
let s = "swift"
let firstTwoCharacters = s.prefix(2)
 
print(firstTwoCharacters)
 
 
 
 
/*
run:
 
sw
 
*/

 



answered Feb 25, 2021 by avibootz
...