2012-10-19 26 views
0

林分離具有我從數據庫中檢索的圖像陣列,我想要檢索圖像陣列中圖像的名字,我想這一點,它不工作,如何將一個圖像的名字從陣列

- (NSString *)convertToDisplayName 
{ 
    NSMutableString *displayName = [[name mutableCopy] autorelease]; 
    [displayName replaceOccurrencesOfString:@".png" withString:@"" 
    options:NSLiteralSearch range:NSMakeRange(0, displayName.length)]; 
    [displayName replaceOccurrencesOfString:@"_" withString:@" " 
    options:NSLiteralSearch range:NSMakeRange(0, displayName.length)]; 
    return displayName; 
} 

請幫助我。提前感謝?

+0

你能提供你的輸入數據的例子,所需的輸出? – sergio

+0

什麼是數組格式? – xfx

+0

@xfx nsmuttable陣列 – Fazil

回答

1

更小,

- (NSString *) convertToDisplayName:(NSString *) actual 
{ 
    return [[actual stringByReplacingOccurrencesOfString:@".png" withString:@""] stringByReplacingOccurrencesOfString:@"_" withString:@" "]; 
} 

NSLog("@Result : %@",[self convertToDisplayName:@"test_file.png"]); 

結果:測試文件

+0

它的工作,感謝兄弟 – Fazil

+0

高興的是可以幫助你!快樂編碼! :) – Hemang

0

試試這個代碼行:

- (NSString *)convertToDisplayName 
{ 
    NSMutableString *displayName = [[name mutableCopy] autorelease]; 
    [displayName replaceOccurrencesOfString:@".png" withString:@"" 
    options:0 range:NSMakeRange(0, displayName.length)]; 
    [displayName replaceOccurrencesOfString:@"_" withString:@" " 
    options:0 range:NSMakeRange(0, displayName.length)]; 
    return displayName; 
}