Tuesday, April 5, 2011

Difference between NSString: isEqualTo and NSString: compare

isEqualTo is used for comparing the value of string.

for e.g.

NSString *a=@"Reetu";
NSString *b=@"Mike";
NSString *c=@"Mike";

if([a isEqualTo:b]) -> It will return No;
if([c isEqualTo:b]) -> It will return YES;

compare is used comparing(generally for sorting the string) by lexical order(in dictionary which string will come first).

if([a compare:b]) -> It will return 1;
if([b compare:a]) -> It will return -1;

No comments:

Post a Comment