How to search with whole word in iPhone?

I have added a search bar with UITableView. when I enter the first character then it search all records starting with that character but when i enter the next character then it search nothing.

Kindly help me. If this is a silly question then kindly be patient and guide me Thanx

Code

-(void)searchData:(NSString*)search{

//    search = [search uppercaseString];

    NSLog(@"Array count233 : %d", [menuArray count]);



    NSLog(@"Array count237 : %d", [menuArray count]);

    NSLog(@"Search String : %@", search);
    if ([search isEqualToString:@""]) {

    }
    else {

        [tableMenuArray removeAllObjects];

            for (int i = 0; i < [menuArray count]; i++) {
                if ([[[menuArray objectAtIndex:i] itemName] hasPrefix:search]) {
                    [tableMenuArray addObject:[menuArray objectAtIndex:i]];
                    NSLog(@"Found");
                }
            }
        }
    [menuTableView reloadData];
}

Answers


If you uncomment the 2nd line, then change this line -

if ([[[menuArray objectAtIndex:i] itemName] hasPrefix:search])

...to -

if ([[[[menuArray objectAtIndex:i] itemName] uppercaseString] hasPrefix:search])

Otherwise you're comparing all-uppercase to normally-cased words. Hope this sorts it for you!


Need Your Help

Python: Join multiple components to build a URL

python url-parsing

I am trying to build a URL by joining some dynamic components. I thought of using something like os.path.join() BUT for URLs in my case. From research I found urlparse.urljoin() does the same thing.

Console log outputting the entire function instead of what's being returned

javascript function nested

I'm just starting to learn JavaScript and decided to make a Rock-Paper-Scissors game with the limited knowledge I've gained so far. However, I cannot figure out why it outputs