我有一个从数据库中检索到的图像数组,我想检索图像数组中的图像名称,我试过这个,它没有用,
- (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 :(得分:1)
更小,
- (NSString *) convertToDisplayName:(NSString *) actual
{
return [[actual stringByReplacingOccurrencesOfString:@".png" withString:@""] stringByReplacingOccurrencesOfString:@"_" withString:@" "];
}
NSLog("@Result : %@",[self convertToDisplayName:@"test_file.png"]);
结果:测试文件
答案 1 :(得分: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;
}