How to get the first N characters from string in Swift

1 Answer

0 votes
let s = "swift java python c c++"
 
let N = 5 
 
let r = s.index(s.startIndex, offsetBy: 0)..<s.index(s.startIndex, offsetBy: N)
 
let substring  = s[r]
 
print(substring)
 
 
 
  
/*
run:
  
swift
  
*/

 



answered Nov 9, 2020 by avibootz

Related questions

2 answers 181 views
2 answers 269 views
1 answer 189 views
1 answer 172 views
2 answers 252 views
1 answer 186 views
...