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.
Asked
Active
Viewed 104 times
-3
-
[string lastPathComponent]. – Saurabh Prajapati Aug 19 '15 at 11:51
-
1Your strings seem to be paths. Maybe you can reflect that in the question and its title. – Felix Aug 19 '15 at 12:09
3 Answers
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