user1416377
user1416377

Reputation: 1

Retrieve the substring of a strings which are in array

I am new to iphone.I have an array which contains the objects like below

"04_Num/04Num001.mp3",
"04_Num/04Num002.mp3",
"04_Num/04Num003.mp3",
"04_Num/04Num004.mp3",
"04_Num/04Num005.mp3",
"04_Num/04Num006.mp3",
"04_Num/04Num007.mp3",
"04_Num/04Num008.mp3",
"04_Num/04Num009.mp3",
"04_Num/04Num010.mp3",
"04_Num/04Num011.mp3",
"04_Num/04Num012.mp3",
"04_Num/04Num013.mp3",
"04_Num/04Num014.mp3",
"04_Num/04Num015.mp3",
"04_Num/04Num016.mp3",
"04_Num/04Num017.mp3",
"04_Num/04Num018.mp3",
"04_Num/04Num019.mp3",
"04_Num/04Num020.mp3",
"04_Num/04Num021.mp3",
"04_Num/04Num022.mp3",
"04_Num/04Num023.mp3",
"04_Num/04Num024.mp3",
"04_Num/04Num025.mp3",
"04_Num/04Num026.mp3",
"04_Num/04Num027.mp3",
"04_Num/04Num028.mp3",
"04_Num/04Num029.mp3",
"04_Num/04Num030.mp3",
"04_Num/04Num031.mp3",
"04_Num/04Num032.mp3",
"04_Num/04Num033.mp3",
"04_Num/04Num034.mp3",
"04_Num/04Num035.mp3",
"04_Num/04Num036.mp3"

but here i want retrieve the strings(objects)only after the / (i.e) for example 04_Num/04Num033.mp3 in this i want only the string 04Num033.mp3.Like this for all the above and then i have to place in an array

how it is possible if any body know this please help me...

Upvotes: 0

Views: 50

Answers (2)

Shyam Bhat
Shyam Bhat

Reputation: 1600

You can separate the string into two parts using NSString's

componentsSeparatedByString:

method, and use the last string component

// Let's call your array of strings as stringsArray
NSMutableArray *prefixStrings = [[NSMutableArray alloc] init];

for (NSString *str in stringsArray) {
    NSArray *stringComponents = [str componentsSeparatedByString:@"/"];
    if ([stringComponents count]) {
        [prefixStrings addObject:[stringComponents objectAtIndex:1]];
    } }

Upvotes: -1

Alladinian
Alladinian

Reputation: 35646

lastPathComponent is what you need. You could do it like so:

NSMutableArray *files = [[NSMutableArray alloc] initWithCapacity:0];
for (NSString *file in songs) //Where songs is the array with the paths you have provided
{
    [files addObject:[file lastPathComponent]];
}

Upvotes: 2

Related Questions