Skip to main content
added 22 characters in body
Source Link
Warif Akhand Rishi
  • 24.3k
  • 8
  • 82
  • 109

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin"   str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 

##Swift 4

substring(to:) and substring(from:) are deprecated in Swift 4.

String(str[..<startIndex]) // "My " String(str[startIndex...]) // "String" String(str[startIndex...endIndex]) // "Strin" 

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin"   str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 

##Swift 4

substring(to:) and substring(from:) are deprecated in Swift 4.

str[..<startIndex] // "My " str[startIndex...] // "String" str[startIndex...endIndex] // "Strin" 

##Swift 2 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin" str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 

##Swift 4

substring(to:) and substring(from:) are deprecated in Swift 4.

String(str[..<startIndex]) // "My " String(str[startIndex...]) // "String" String(str[startIndex...endIndex]) // "Strin" 
added 162 characters in body
Source Link
Warif Akhand Rishi
  • 24.3k
  • 8
  • 82
  • 109

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin" str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 

##Swift 4

substring(to:) and substring(from:) are deprecated in Swift 4.

str[..<startIndex] // "My " str[startIndex...] // "String" str[startIndex...endIndex] // "Strin" 

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin" str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin" str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 

##Swift 4

substring(to:) and substring(from:) are deprecated in Swift 4.

str[..<startIndex] // "My " str[startIndex...] // "String" str[startIndex...endIndex] // "Strin" 
added 285 characters in body
Source Link
Warif Akhand Rishi
  • 24.3k
  • 8
  • 82
  • 109

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin" str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 2.0 Simple

let str = "My String" let subStr = str[str.startIndex.advancedBy(3)...str.startIndex.advancedBy(7)] //"Strin" 

##Swift 3

let startIndex = str.index(str.startIndex, offsetBy: 3) let endIndex = str.index(str.startIndex, offsetBy: 7) str[startIndex...endIndex] // "Strin" str.substring(to: startIndex) // "My " str.substring(from: startIndex) // "String" 
Source Link
Warif Akhand Rishi
  • 24.3k
  • 8
  • 82
  • 109
Loading