微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NSMutableArray中的元素的字符串转换

如何解决NSMutableArray中的元素的字符串转换

| 因此,我有一个“ 0”,其中包含要在“ 1”中显示的文档名称。 ѭ0中的ѭ2具有空格,因此条目看起来像\“ John Smith \”。然后,我有对应于每个表条目的pdf。这些pdf条目名称不同。它们将类似于\“ JohnSmith.pdf \”。我创建了一种将名称基本上转换为pdf的方法,以呈现适当的pdf。在我的方法中,我基本上将值硬编码
NSUInteger loopCount = 0;
for ( ; loopCount < [array count]; loopCount++) {
    if ([[array objectAtIndex:loopCount] isEqualToString:@\"John Smith\"]) {
        [array replaceObjectAtIndex:loopCount withObject:@\"JohnSmith.pdf\"];
    }
}
一个更好的方法吗?这就是我想到的全部,因为数据已经被命名为不同的名称。谢谢。     

解决方法

        也许您可以使用类似以下的内容:
NSString *filename = [[name stringByReplacingOccurrencesOfString:@\" \" withString:@\"\"] stringByAppendingPathExtension:@\"pdf\"];
    ,        
 NSUInteger loopCount = 0;
 for ( ; loopCount < [array count]; loopCount++) {
    NSString* name = [array objectAtIndex:loopCount];
    [array replaceObjectAtIndex:loopCount withObject:[NSString stringWithFormat@\"%@.pdf\",[name stringByReplacingOccurrencesOfString:@\" \" withString:@\"\"]]];
}
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。