Comparing text in UITextView?

后端 未结 4 881
感动是毒
感动是毒 2021-01-29 10:08

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?

相关标签:
4条回答
  • 2021-01-29 10:26
     if([textfield.text isEqualToString:yourtext])
    {
       //true;
    }
    else
    {
    //false
    }
    
    0 讨论(0)
  • 2021-01-29 10:32

    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.

    0 讨论(0)
  • 2021-01-29 10:38

    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 ] )
    {}
    
    0 讨论(0)
  • 2021-01-29 10:38

    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];
    
    0 讨论(0)
提交回复
热议问题