user1268135
user1268135

Reputation: 57

How to retrieve the substring with in the string

I am new to iphone.I have small doubt that is I have a path of my audiofile which is placed in the directory in resources folder that path is

/Users/Chary/Library/Application Support/iPhone Simulator/5.0/Applications/B02404E5-52DC-49B6-8DBB-C9946E4331AF/BiblePlayer.app/raj/1.mp3

My question is how to retrieve the string "1.mp3" from that entire path?

Upvotes: 1

Views: 75

Answers (3)

Nikhil Bansal
Nikhil Bansal

Reputation: 1545

try it:-

NSString *yourPath = @"/Users/Chary/Library/Application Support/iPhone Simulator/5.0/Applications/B02404E5-52DC-49B6-8DBB-C9946E4331AF/BiblePlayer.app/raj/1.mp3";
NSString *fileName = [yourPath lastPathComponent];

It may help u thank :)

Upvotes: 1

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

NSString *allString = @"/Users/Chary/Library/Application Support/iPhone Simulator/5.0/Applications/B02404E5-52DC-49B6-8DBB-C9946E4331AF/BiblePlayer.app/raj/1.mp3"

int slashPosition = [allString rangeOfString:@"/" options:NSBackwardsSearch].location;
    NSString *function = [allString substringFromIndexslashPosition + 1];

This will get you the path of the file after the last slash

Upvotes: 1

zoul
zoul

Reputation: 104065

NSString *fullPath = @"…";
NSString *fileName = [fullPath lastPathComponent];

Upvotes: 4

Related Questions