不区分大小写的 NSString 比较
使用此代码我可以比较字符串值。
[elementName isEqualToString: @"Response"]
但这是区分大小写的。有没有办法比较字符串而不区分大小写?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
NSString
上有一个caseInsensitiveCompare:
方法,为什么不阅读 文档?该方法返回NSComparisonResult
:…啊,抱歉,刚才我意识到您要求区分大小写相等。 (为什么我不阅读这个问题?:-)默认的
isEqual:
或isEqualToString:
相等性应该已经区分大小写,这是什么情况?There’s a
caseInsensitiveCompare:
method onNSString
, why don’t you read the documentation? The method returnsNSComparisonResult
:…ah, sorry, just now I realized you are asking for case sensitive equality. (Why don’t I read the question? :-) The default
isEqual:
orisEqualToString:
equality should already be case sensitive, what gives?以下是您需要比较字符串而不关心它是小写还是大写的代码:
Here's the code you would need to compare a string without caring about whether it's lowercase or uppercase:
实际上 isEqualToString: 具有区分大小写的能力。
as:
如果您想要求不区分大小写的比较,那么这里是代码:
您可以将两个可比字符串更改为小写或大写,并且可以比较为:
Actually isEqualToString: works with case sensitive ability.
as:
if you want to ask for case insensitive compare then here is the code:
You can change both comparable string to lowerCase or uppercase, and can compare as: