不区分大小写的NSString比较 [英] Case-insensitive NSString comparison

查看:347
本文介绍了不区分大小写的NSString比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码我可以比较字符串值。

Using this code I am able to compare string values.

[elementName isEqualToString: @"Response"]

但这种情况下比较敏感。有没有办法比较不区分大小写的字符串?

But this compares case-sensitively. Is there a way to compare the string without case sensitivity?

推荐答案

有一个 caseInsensitiveCompare:方法 NSString ,为什么不读文档?该方法返回 NSComparisonResult

There’s a caseInsensitiveCompare: method on NSString, why don’t you read the documentation? The method returns NSComparisonResult:

enum {
   NSOrderedAscending = -1,
   NSOrderedSame,
   NSOrderedDescending
};
typedef NSInteger NSComparisonResult;

...啊,对不起,刚才我意识到你要求区分大小写>平等。 (为什么我不读这个问题?:-)默认 isEqual: isEqualToString:区分大小写,是什么给了?

…ah, sorry, just now I realized you are asking for case sensitive equality. (Why don’t I read the question? :-) The default isEqual: or isEqualToString: equality should already be case sensitive, what gives?

这篇关于不区分大小写的NSString比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆