两个字符串比较中的问题......!

时间:2009-09-11 16:21:59

标签: iphone

LotteryAppDelegate * appDelegate =(LotteryAppDelegate *)[[UIApplication sharedApplication] delegate];     Lotterycheck *检查;

//NSString *trueval;
 BOOL found = NO;
    NSUInteger f;
for (f = 0; f < [appDelegate.books count]; f++) {



    check = [appDelegate.books objectAtIndex:f];

    checkthis = [NSString stringWithFormat:@"%@", check.LotteryNumber];


    mystring =@"1234567"; //check.LotteryNumber;
    NSString *finel = checkthis;
    NSLog(@"Dynamic Value: %@",finel);
    NSLog(@"Static Value: %@",mystring);

    if ([mystring isEqualToString:finel]) {
        found = YES;
        [self showalert:finel];
        break;

    }

它没有合成字符串“if([mystring isEqualToString:finel])”mystring是静态值而finel是我从类lotterycheck获得的值..

1 个答案:

答案 0 :(得分:1)

假设属于appDelegate.books的对象属于Book类,请尝试以下代码片段。

BOOL found = NO;
NSString *mystring = @"1234567";

for (Book *book in appDelegate.books) {

     NSString *checkthis = [NSString stringWithFormat:@"%@", book.LotteryNumber];

     if ([mystring isEqualToString checkthis]) {
        found = YES;
        [self showalert:checkthis];
        break;

    }
}