. 1 NSString the urlString * = @ " http://www.baidu.com/img/baidu_logo_fqj_10.gif " ; 2 // Method a: The most direct . 3 NSString * fileName = [the urlString lastPathComponent]; . 4 NSLog ( @ " fileName == @% " , fileName); . 5 // method two: The segmentation characters or strings . 6 NSString filename2 * = [[NSString the alloc] the init]; . 7 NSArray separatedArray * = [[NSArray the alloc] the init]; . 8 separatedArray = [the urlString componentsSeparatedByString: @ " / " ]; . 9 = filename2 [separatedArray lastObject]; 10 NSLog ( @ " separatedArray ==% @ " , separatedArray); . 11 NSLog ( @ " filename2 ==% @ " , filename2); 12 is // Method three: as a link Road King 13 is NSArray urlCom * = [[NSArray the alloc] initWithArray: [the urlString pathComponents]]; 14 NSLog ( @ " [urlCom lastObject] ===% @ " , [urlCom lastObject]); 15 // method IV: NSRange it. interception of binary files is very convenient when 16 NSString * filename3; 17 NSRange the Range = [urlString rangeOfString:@ " / " Options: NSBackwardsSearch]; // NSBackwardsSearch retrieved from the start end of the string 18 is IF (range.location =! NSNotFound) { . 19 filename3 = [the urlString substringFromIndex: range.location + . 1 ]; 20 is IF ([[filename3 lowercaseString] hasSuffix: @ " .gif " ]) { // lowercaseString change uppercase to lowercase letters cut letters uppercaseString change capitalizedString initial capital letters converter · 21 is NSLog ( @ " filename3 ====% @ " , filename3); 22 is } the else { 23 is 24 } 25 }else{ 26 27 }
iOS obtain network data file name / path
Guess you like
Origin www.cnblogs.com/wanli-leon/p/12148776.html
Recommended
Ranking