nsstring - Comparing 2 strings in Objective-C -
i have nstask
of output stored in nsdata
object. string via
nsstring *outputstring = [[nsstring alloc] initwithdata:outputdata encoding:nsutf8stringencoding];
now can nslog
string , compare via [outputstring isequaltostring:@"nslogged string"]
. result 2 strings not identical. why that? played encoding not seem problem.
the output tool contains trailing newline character. either compare against "yourexpectedstring\n"
or use like
outputstring = [outputstring stringbytrimmingcharactersinset:[nscharacterset newlinecharacterset];
to remove newline characters.
Comments
Post a Comment