iPhone:在另一个字符串中找到一个字符串insensetive [英] iPhone: find one string in another with case insensetive
本文介绍了iPhone:在另一个字符串中找到一个字符串insensetive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题类似于如何检查字符串是否包含Objective-C中的其他字符串?
我如何检查字符串(NSString)是否包含另一个较小的字符串但忽略大小写?
How can I check if a string (NSString) contains another smaller string but with ignoring case?
NSString *string = @"hello bla bla";
我希望得到类似的东西:
I was hoping for something like:
NSLog(@"%d",[string containsSubstring:@"BLA"]);
无论如何,有没有办法找到一个字符串是否包含另一个带有忽略大小写的字符串?但请不要将两个字符串转换为UpperCase或LowerCase。
Anyway is there any way to find if a string contains another string with ignore case ? But please do not convert both strings to UpperCase or to LowerCase.
推荐答案
与链接中提供的答案类似,但请使用 options
。
As similar to the answer provided in the link, but use options
.
参见 - (NSRange)rangeOfString:(NSString *)aString选项: (NSStringCompareOptions)掩码
在 Apple doc
NSString *string = @"hello bla bla";
if ([string rangeOfString:@"BLA" options:NSCaseInsensitiveSearch].location == NSNotFound)
{
NSLog(@"string does not contain bla");
}
else
{
NSLog(@"string contains bla!");
}
这篇关于iPhone:在另一个字符串中找到一个字符串insensetive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文