1

I'm going crazy with substrings in Swift. I need to get the actual index of a "string" inside another string to determine the range of my final output.

Any ideas? Thanks

Sara Canducci
  • 6,231
  • 5
  • 19
  • 24
  • 2
    http://stackoverflow.com/questions/24029163/finding-index-of-character-in-swift-string ? – Larme Aug 29 '14 at 11:52

1 Answers1

3
let yourString = "loremipsumSTRINGdolor" as NSString
let range: NSRange = yourString.rangeOfString("STRING")
let lenght =  range.length
let location = range.location

This should do.

EDIT: Fix.

tmagalhaes
  • 944
  • 9
  • 12