How to remove the first and the last character from a string in Swift

1 Answer

0 votes
var s = "swift java c++ c python"
 
print(s)

var substring = s[s.index(s.startIndex, offsetBy: 1)..<s.endIndex]

substring = substring.dropLast()   
 
print(substring)
  
  
 
  
/*
run:
  
swift java c++ c python
wift java c++ c pytho
  
*/

 



answered Feb 27, 2021 by avibootz

Related questions

1 answer 250 views
1 answer 104 views
1 answer 195 views
1 answer 158 views
4 answers 289 views
3 answers 256 views
...