I am trying to figure out how to get a range of a substring within a string. By range I mean where the substring begins and where it ends. So if I have following string example:
NSString *testString=@"hello everyone how are you doing today?Thank you!";
If the substring I am looking for (in this example) is "how are you doing", then the beginning range should be 15 and the ending range should 31.
(15, 31)
Can anyone tell me how I could do this programatically? Thank you!
Best Answer
You can use the method
-rangeOfString
to find the location of a substring in a string. You can then compare the location of the range to NSNotFound to see if the string actually does contain the substring.