开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜