Skip to main content
2 of 2
added 39 characters in body
Oliver Dixon
  • 7.5k
  • 6
  • 72
  • 101

Easy solution with little code.

Make an extension that includes basic subStringing that nearly all other languages have:

extension String { func subString(start: Int, end: Int) -> String { let startIndex = self.index(self.startIndex, offsetBy: start) let endIndex = self.index(startIndex, offsetBy: end) let finalString = self.substring(from: startIndex) return finalString.substring(to: endIndex) } } 

Simply call this with

someString.subString(start: 0, end: 6) 
Oliver Dixon
  • 7.5k
  • 6
  • 72
  • 101