compare nsstring

Comparing NSString in Objective-C

To compare two NSString objects in Objective-C, you can use the isEqualToString: method. This method returns a Boolean value indicating whether the receiver and the specified string are equal.

Here's an example of how to use the isEqualToString: method:

NSString *string1 = @"Hello";
NSString *string2 = @"World";

if ([string1 isEqualToString:string2]) {
    NSLog(@"The strings are equal");
} else {
    NSLog(@"The strings are not equal");
}

In this example, the isEqualToString: method is used to compare string1 and string2. If the strings are equal, the message "The strings are equal" will be printed. Otherwise, the message "The strings are not equal" will be printed.

Please note that the isEqualToString: method performs a case-sensitive comparison. If you need to perform a case-insensitive comparison, you can use the caseInsensitiveCompare: method instead.

I hope this helps!