How to get string from a long string?
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.
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.
精彩评论