tags:

views:

55

answers:

2

hi ,

here is my code :

NSUInteger f;
  for (f = 0; f < [appDelegate.books count]; f++) {
    check = [appDelegate.books objectAtIndex:f];

 checkthis = check.LotteryNumber;


        mystring = check.LotteryNumber;
 NSLog(@"Dynamic Value: %@",mystring);
 NSLog(@"Static Value: %@",checkthis);

 if (checkthis == mystring) {
        found = YES;
        break;
    }
 printf("In LOOP");
}
if ( found ) {
    // do found
 NSLog(@"Found");
} else {
    // do not found
 NSLog(@"not Found");
}


 //if (checkthis == mystring) {

in above line if i place checkthis on both side , its working , but when i am taking a dynamic value its not working.. i also tried like this

if(checthis isEqualToString mystring)

same problem here ....

Thanks in advance

+3  A: 

You're using pointer comparison and not string comparison.

You should be using:

if([checkThis isEqualToString:myString]) { ...
Dave DeLong
looks like you are missing a ']' there :)
crashmstr
@crashmstr whoops! thanks. =)
Dave DeLong
A: 

You are using comparision by pointer the comparison you made checks memory a ddresses and will only return true if its the same object being compared, you should use [string isEqualToString:otherString] method from NSString instead

Daniel
as i explained in the question i have also tried that..like this if([string1 isEqualToString:string2] my first string i static i used like this NSString *string1 =@"1234567";and in string2 i have the value coming from the xml parse...i checked that value by nslog its same as the string 1 , but it doesn't true the condition..
Chris
are they actaully equal tho? NSLog both strings maybe you have an exstra space there, or something of the sort
Daniel
Yes ... i used nslog to check that its true or not , but the condition is always true ...:)
Chris