2012-06-18 85 views
0

我是新來iphone.I有一個包含類似下面檢索字符串這是在陣列

"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" 

,但在這裏,我想檢索字符串(對象)的對象數組的子後才/ (即)例如04_Num/04Num033.mp3在這個我只想要字符串04Num033.mp3.Like這個爲所有上述,然後我必須放置在一個數組

如何有可能,如果任何機構知道這一點幫我...

回答

2

lastPathComponent是你所需要的。你可以做到這一點,像這樣:

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]]; 
} 
-1

可以使用的NSString的

componentsSeparatedByString字符串分隔成兩個部分:

方法,並使用最後一個字符串組成

// 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]]; 
    } }