开发者

NSPredicate and NSString Question

I have the following predicate that works fine with numbers such as 555 and 623 (3 digit numbers)

The problem is, I have numbers such as 005 and 009 etc (1 digit with two 0 before).

NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"ANY code BETWEEN %@",
                                    [NSArray arrayWithObjects: 
                                     [NSExpression expressionForConstantValue: [NSNumber numberWithFloat: [self.predicateFilter floatValue]]],
                                     [NSExpression expressionForConstantValue: [NSNumber numberWithFloat: [self.predicateFilter floatValue] + .99]],
                                     nil]];

Most of the time, predicateFilter will be a string with number like @"124". But when I run a number like 035 (notice the 0 at beggining), I get the following NSLog:

2011-08-13 18:32:23.989 Codes[2007:707] code 004
2011-08-13 18:32:24.018 Codes[2007:707] ANY code BETWEEN {4, 4.99}
2011-08-13 18:34:23.846 Codes[2007:707] code 083
2011-08-13 18:34:23.864 Codes[2007:707] ANY code BETWEEN {83, 83.99}

So it is n开发者_开发百科ot finding those numbers because of the 00X.

Is there a way I can do an if/else or something that catches all numbers that have a 0 or 00 to begin with, so I can edit the predicate accordingly?

EDIT:

I think I just need to make a predicate that matches the first 3 digits of code to an NSString, which as 005. Then that would give me the rest of the results that are 005.5, 005.6, etc.


Since code is a string can you do a MATCH comparison instead, or is this core data. If it is core data can you add a property to return code as an Integer codeInteger perhaps using transient attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜