Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top