Saturday, October 10, 2015

NSString rangeOfString - Search for matching characters in a string

Type these codes in the playground:


let theString = "Hello World$$1234567890" as NSString
let range = theString.rangeOfString("$$")
//The result is:
//range.location = 11
//range.length = 2

let string1 = theString.substringToIndex(range.location)

let string2 = theString.substringFromIndex(range.location+range.length)
//The result is:
//string1 = "Hello World"
//string2 = "1234567890"

No comments:

Post a Comment