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");
}
}
My guess would be that there is some unwanted white space in the strings from the text file. Try changing
isEqualToStringtohasPrefix.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