【发布时间】:2011-08-30 04:17:37
【问题描述】:
我有一个包含文件名的数组,我想找到所有以 e.g. 结尾的名称。 00001.trc 当traceNum 为 1 时。我试过这个:
NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH \"%05d.trc\"", traceNum];
我的谓词是SELF ENDSWITH "%05d.trc" 而不是SELF ENDSWITH "00001.trc"
我试过了:
NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH %@%05d.trc%@", @"\"", traceNum, @"\""];
我遇到了一个例外:Unable to parse the format string "SELF ENDSWITH %@%05d.trc%@"。
所以我尝试了这个:
NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"SELF ENDSWITH \"%05d.trc\"", traceNum]];
它有效。
那么除了predicateWithFormat 之外,我真的还需要stringWithFormat,还是我在创建谓词时做的不对?
【问题讨论】:
标签: cocoa macos nsarray nspredicate