开发者

Ignore case UITextField/UITextView

开发者 https://www.devze.com 2023-01-19 15:05 出处:网络
I would like to ignore all case sensitivity to be ignored for my UITextField and开发者_JAVA技巧 UITextView. I would also like to know how to detect if the string is upperCase or lowerCase. Thanks.[myS

I would like to ignore all case sensitivity to be ignored for my UITextField and开发者_JAVA技巧 UITextView. I would also like to know how to detect if the string is upperCase or lowerCase. Thanks.


[myString uppercaseString] will give you the myString variable transformed to use only uppercase letters, [myString lowercaseString] will give you the lowercase version, respectively.

You can use it to check for uppercase (lowercase) strings like this:

if ([[textField text] isEqualToString:[[textField text] uppercaseString]]) {
    NSLog("String is uppercase!");
}

If you have a reference string and want to compare it ignoring the case, you can just use caseInsensitiveCompare: method of NSString:

[referenceString caseInsensitiveCompare:[textField text]];
0

精彩评论

暂无评论...
验证码 换一张
取 消