问题描述
我想在另一个NSString中搜索NSString,以便即使第二个不以第一个开头也找到结果,例如:
I would like to search for an NSString in another NSString, such that the result is found even if the second one does not start with the first one, for example:
例如:我有一个搜索字符串st。我查看下面的记录,看看下面是否包含这个搜索字符串,所有的都应该返回一个好的结果,因为他们都有st。
eg: I have a search string "st". I look in the following records to see if any of the below contains this search string, all of them should return a good result, because all of them have "st".
餐厅
稳定
Kirsten
现在我正在做下列事情:
At the moment I am doing the following:
NSComparisonResult result = [selectedString compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
这只适用于上述例子中的stable,因为它以st对于其他2.我如何修改这个搜索,以便它返回所有3的确定?
This works only for "stable" in the above example, because it starts with "st" and fails for the other 2. How can I modify this search so that it returns ok for all the 3?
谢谢!!!
推荐答案
为什么不先google?
Why not google first?
NSString *string = @"hello bla bla";
if ([string rangeOfString:@"bla"].location == NSNotFound) {
NSLog(@"string does not contain bla");
} else {
NSLog(@"string contains bla!");
}
这篇关于NSString搜索整个文本的另一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!