How can we compare the text entered in UITextVIew
with my default text in code to determine whether they are both the same or not?
if([textfield.text isEqualToString:yourtext])
{
//true;
}
else
{
//false
}
I think this should work for you:
Though this is a case sensitive comparison of string
BOOL boolVal = [textView.text isEqualToString:@"My Default Text"];
Here is how you can do case insensitive comparison of string:
BOOL boolVal = [textView.text compare:@"My Default Text" options:NSCaseInsensitiveSearch]
Here if boolVal
is YES
then you can say that strings are same else they are different.
Hope this helps you.
You can use the methods of NSString for this.
1: isEqualToString
: (case-sensitive)
if( [ myString isEqualToString: otherString ] )
{}
2: caseInsensitiveCompare
: (case-insensitive)
if( [ myString caseInsensitiveCompare: otherString ] )
{}
3: localizedCaseInsensitiveCompare
: (case-insensitive and localized)
if( [ myString localizedCaseInsensitiveCompare: otherString ] )
{}
First is to compare with the value abc and second is to compare with the String * str
.
[textfield1.text isEqualToString:@"abc"]
or
[textfield1.text isEqualToString:str];