English 中文(简体)
如何使用 UISearch Bar 在数组的字符串中搜索第二个单词?
原标题:How to Search 2nd word in a string of array using UISearchBar?

I have to search a word in an array using UISearchBar. for example i have "Chicken Salad" string in an array at index 2. now if want to search it using last word "Salad" then what should i do? for the time i am using this code and it is working good but if you search from first word.

(appDelegate.isAirlineSelection == YES) {
            for (int i = 0; i < [menuArray count]; i++) {
                if ([[[[menuArray objectAtIndex:i] itemName] uppercaseString] hasPrefix:search]||[[[[menuArray objectAtIndex:i] itemName] uppercaseString] hasSuffix:search]) {
                    [tableMenuArray addObject:[menuArray objectAtIndex:i]];
                    NSLog(@"Found");
                }
            }

帮帮我吧

最佳回答

尝试这个方式, 它会在字词之间搜索 :

for(NSString *name in menuArray)        
{
    if ([name rangeOfString:search options:NSLiteralSearch|NSCaseInsensitiveSearch].location != NSNotFound)
        [tableMenuArray addObject:name];
            NSLog(@"Found");

}
问题回答

首先,您应该将阵列名称分成两个部分,创建两个阵列,然后可以很容易地使用第二个阵列的搜索栏,并找到准确的结果,你要什么。

for (NSString *name in lastnames)
    {

            NSComparisonResult result = [name compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
            if (result == NSOrderedSame)
            {
                [searchedNames addObject:name];
            }

    }




相关问题
Search field with Thickbox issue

i have a search form which is shown with Thickbox inside an iframe. the problem is.. that after i click "search" the result page is shown inside the same iframe! and i want it to be shown in the main ...

Will an incomplete google sitemap hurt my search ranking?

If I submit a sitemap.xml which does not contain all of the pages of my site, will this affect my search ranking? For example: If my sitemap only contained pages that had been created in the last ...

speeding up windows file search with C#

i made a program that search logical drives to find a specific file .if user type file name an click search button , searching begins , but i don t know how to stop searching in the middle of process....

JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

Embed Google/ Yahoo search into a web site or build your own

I am looking for an opinion on the whether to use Google custom search, Yahoo search builder or build my own for web projects (no more than 100 pages of content). If I should build my own - do you ...

热门标签