سؤال

I have a NSTask of which the output is stored in an NSData object. From this I get a string via

NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];

Now I can NSLog this string and then compare it via [outputString isEqualToString:@"NSLogged String"]. The result is that the two strings are not identical. Why is that? I played with the encoding but this does not seem to be the problem.

هل كانت مفيدة؟

المحلول

The output from your tool contains a trailing newline character. So either compare against "yourExpectedString\n" or use something like

outputString = [outputString stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet];

to remove the newline characters.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top