Reputation: 21
I have a string like this:
NSString *aString =
[NSString stringWithFormat:"********************Documents/image%@.jpg",aNumber];
I want to get "Documents/image%@.jpg" out of the string?
What can I do? I want to use "substringFromIndex" but I don't know the index.
Upvotes: 0
Views: 500
Reputation: 10353
You can use rangeOfString
to find the index of "Documents...".
NSString class reference
And then use that with 'substringFromIndex' to get the substring you want. For example:
[astring substringFromIndex:[aString rangeOfString:@"Documents"].location]
You should add error checking to make sure that the range returned by the 'rangeOfString' method is good.
Upvotes: 1