Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top