I have an NSString object and I want to make a substring from it, by locating a word.
For example, my string is: "The dog ate the cat", I want the program to locate the word "ate" and make a substring that will be "the cat".
Can someone help me out or give me an example?
Thanks,
Sagiftw
You can search for a string and then get the searched string into another string...
Try this one..
This method return true or false. If your string contains this character it return true, and otherwise it returns false.
You can use any of the two methods provided in NSString class, like
substringToIndex:
andsubstringFromIndex:
. Pass a NSRange to it as your length and location, and you will have the desired output.If you want to trim whitespace you can do that separately.
What about this way? It's nearly the same. But maybe meaning of NSRange easier to understand for beginners, if it's written this way.
At last, it's the same solution of jtbandes