如何将图像名称与数组分开

时间:2012-10-19 11:59:38

标签: iphone ios nsmutablearray

我有一个从数据库中检索到的图像数组,我想检索图像数组中的图像名称,我试过这个,它没有用,

  - (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;
 }

请帮帮我。谢谢你提前?

2 个答案:

答案 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;
 }