Final application will look like:
In this tutorial will learn how to compare two string in iPhone using Comparestring(), when button is clicked. This application is window Based Application, will set action for the button and whenever button is clicked will show result. my project name is compareString().
Add this in .h file:
IBOutlet UIButton *show;
@property (nonatomic, retain) IBOutlet NSString *string;
@property (nonatomic, retain) IBOutlet UIButton *show;
Add this in .m file:
@synthesize window, string, show;
NSString *string1 = @"Rose"; // assigning value to string
NSString *string2 = @"India"; // assigning value to string
int val=[string1 compare: string2]; // in it we declare it as integer type
NSString *s=[[NSString alloc] initWithFormat:@"Value is: %d",val];
// here we alloc it and is printed by using NSLog.
make connection of button in Interface Builder as below.
In this we are writing the method for action here we are taking two string and comparing,
1 indicates strings are not equal and 0 indicates strings are equal.