0

I'm trying to get a word from a label and compare it to an text file, but for some reason I get "no" for a response no matter what i do. is there something wrong with the code.

wordS1 = [[NSBundle mainBundle] pathForResource:@"c" ofType:@"txt"];
wordS2 = [NSString stringWithContentsOfFile:wordS1 encoding:NSUTF8StringEncoding error:nil];        
wordArray = [wordS2   componentsSeparatedByString:@"\n"];


for (compare = 0 ; compare != 58; compare++) 
{

    if ( [word.text isEqualToString:[wordArray objectAtIndex:compare]]) 
    {
        NSLog(@"Yes");    

    }
    else
    {
        NSLog(@"No");
    }


}
jusuf
  • 21
  • 5

1 Answers1

0

My guess would be that there is some unwanted white space in the strings from the text file. Try changing isEqualToString to hasPrefix.

EDIT: that's actually not the best way to do it. Look here for removing the whitespace from the string Collapse sequences of white space into a single character and trim string

Community
  • 1
  • 1
edc1591
  • 10,146
  • 6
  • 40
  • 63