tags:

views:

31

answers:

2

how would i compare two strings if they are not equal? i cannot use isEqualToString ... i am very new to the language..plz help thanks!!!

+1  A: 

Use the NSString compare method (or one of the more detailed variations).

walkytalky
A: 

Steps:

  1. Check if both the strings are of equal length.

    using ObjectiveC :


    [str1 length] == [str2 length];

  2. If both the strings are of equal length, then compare character by character.

    using ObjectiveC:


BOOL isStringsEqual = YES; for(int i=0; i < [str1 length]; i++) { if([str1 characterAtIndex:i] != [str2 characterAtIndex:i]) { isStringsEqual = NO; break; } }

if(isStringsEqual) { NSlog(@"Both strings are equal"); } else { NSlog(@"Both strings are not equal"); }

Biranchi