如果string是“Testing for Group”,那么如何查找“rou”是否为子串。
使用此链接上的方法
仅提供完整字,如子字符串是否存在。
喜欢上面的字符串中的“for”,但是我想找到“或”,“rou”就像字符串中存在的字符串一样。
怎么做?
提前致谢。
编辑:
我的代码
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
int count=0;
arrayGroupName=[[NSMutableArray alloc]init];
if ([searchText isEqualToString:@""])
{
arrayGroupName=permArrayGroupName;
}
else
{
while (count!=[permArrayGroupName count])
{
if ([[[[permArrayGroupName objectAtIndex:count] objectGroupName]capitalizedString] rangeOfString:[searchText capitalizedString]].location == NSNotFound )
{
NSLog(@"string does not contain bla");
}
else
{
NSLog(@"found");
[arrayGroupName addObject:[permArrayGroupName objectAtIndex:count]];
}
/*if ([[[[permArrayGroupName objectAtIndex:count] objectGroupName]capitalizedString] hasPrefix:[searchText capitalizedString]])
{
[arrayGroupName addObject:[permArrayGroupName objectAtIndex:count]];
}*/
count++;
}
}
[tableGroupList reloadData];
}
答案 0 :(得分:1)
以下作品:
NSString *string=@"Testing for Group";
if ([string rangeOfString:@"rou"].location == NSNotFound) {
NSLog(@"Not found");
}
else {
NSLog(@"Found");
}