2

I have just coverted an app from swift3 to swift4.2 on Xcode 10.1

I am in the process of fixing some of the many errors that have appeared. Apparently substring(from:)' is deprecated. Use string slicing subscript with a 'partial range from' operator

t_prefix_phone = contact_phone.substring(to:contact_phone.index(contact_phone.startIndex, offsetBy: 3))

t_phone = contact_phone.substring(from:contact_phone.index(contact_phone.endIndex, offsetBy: -7))

Could you please help me translate the code above to 4.2 in such a way that the results are still strings.

Thanks

Johny D Good
  • 427
  • 1
  • 8
  • 26
  • Possible duplicate of [How can I use String slicing subscripts in Swift 4?](https://stackoverflow.com/questions/45562662/how-can-i-use-string-slicing-subscripts-in-swift-4) – Andrew21111 Mar 18 '19 at 11:37

1 Answers1

7

swift 4 has prefix and suffix just for this:

    let contact_phone = "0123456789"
    let t_prefix_phone = String(contact_phone.prefix(3))
    let t_phone = String(contact_phone.suffix(7))
Johny D Good
  • 427
  • 1
  • 8
  • 26