NSMutableArray中元素的字符串转换

Cry*_*tal 0 iphone objective-c

所以我有一个NSArray有文件名称的文件UITableView.将NSString在S NSArray有空格这样一个条目会是什么样子,"约翰·史密斯".然后我有对应于每个表条目的pdf.这些pdf条目名称不同.它们就像是"JohnSmith.pdf".我创建了一个方法,基本上将名称转换为pdfs,以呈现适当的pdf.在我的方法中,我基本上硬编码了值

NSUInteger loopCount = 0;
for ( ; loopCount < [array count]; loopCount++) {
    if ([[array objectAtIndex:loopCount] isEqualToString:@"John Smith"]) {
        [array replaceObjectAtIndex:loopCount withObject:@"JohnSmith.pdf"];
    }
}
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?这就是我所能想到的,因为数据已经被赋予了不同的名称.谢谢.

Mat*_*uch 6

也许你可以使用这样的东西:

NSString *filename = [[name stringByReplacingOccurrencesOfString:@" " withString:@""] stringByAppendingPathExtension:@"pdf"];
Run Code Online (Sandbox Code Playgroud)