Comparing text in UITextView?

后端 未结 4 882
感动是毒
感动是毒 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: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.

提交回复
热议问题