开发者

How to store last part of string?

开发者 https://www.devze.com 2023-03-16 05:09 出处:网络
I have a string as 开发者_运维百科 http://www.google.co.uk/ig/images/weather/partly_cloudy.gif.

I have a string as 开发者_运维百科 http://www.google.co.uk/ig/images/weather/partly_cloudy.gif. I need to save only the partly_cloudy.gif .How do i select obly that part of string?


If you are sure that it represents a path then you can call the lastPathComponent method on it.

Usage

NSString * link = @"http://www.google.co.uk/ig/images/weather/partly_cloudy.gif";
NSLog(@"%@", [link lastPathComponent]);


Use the NSString function componentsSeparatedByString. For example, NSString *url = @"http://www.google.com/1/2/3/test.gif"; NSArray *components = [url componentsSeparatedByString:@"/"]; would give you an NSArray of all strings in between a '/' character.

NSString reference: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

0

精彩评论

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