Sara Canducci
Sara Canducci

Reputation: 6291

How to Substring in Swift

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

Upvotes: 1

Views: 2898

Answers (1)

tmagalhaes
tmagalhaes

Reputation: 984

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

This should do.

EDIT: Fix.

Upvotes: 3

Related Questions