How to get substring based on the string index in Swift

2 Answers

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

 



answered Nov 9, 2020 by avibootz
edited Nov 9, 2020 by avibootz
0 votes
let s = "swift java python c c++"

let r = s.index(s.startIndex, offsetBy: 6)..<s.index(s.endIndex, offsetBy: -6)

let substring  = s[r]

print(substring)



 
/*
run:
 
java python
 
*/

 



answered Nov 9, 2020 by avibootz
edited Nov 9, 2020 by avibootz
...