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

请帮助我。提前谢谢?

4

2 回答 2

1

再小一点,

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

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

结果:测试文件

于 2012-10-19T12:24:38.640 回答
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;
 }
于 2012-10-19T12:13:58.683 回答