-3

I have a string /uploads/images/mypic_123.png now i want to get only image name like mypic_123.png.Please tell me how to do it? I am using objective-c.

mah
  • 39,056
  • 9
  • 76
  • 93
TechChain
  • 8,404
  • 29
  • 103
  • 228

3 Answers3

3

NSString has a method named lastPathComponent that you can use

Leonardo
  • 1,740
  • 18
  • 27
2

you can use this way:-

 NSURL *url;
 NSString *substring=[url lastPathComponent];
 NSLog(@"Your image name is :%@",substring);
Sahil Manchal
  • 472
  • 6
  • 20
Ram Vinay Yadav
  • 105
  • 2
  • 8
1

You may also use the below code

NSString *str = @"/uploads/images/mypic_123.png";
NSArray *parts = [str componentsSeparatedByString:@"/"];
NSString *filename = [parts lastObject];
Sahil Manchal
  • 472
  • 6
  • 20
Rajat
  • 10,977
  • 3
  • 38
  • 55