Amazon.com Widgets 15.2 Exercise
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 09:18:00 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 15
| | |-+  15.2 Exercise
Pages: [1]   Go Down
Print
Author Topic: 15.2 Exercise  (Read 220 times)
rue
Jr. Member
**
Posts: 53






« on: June 20, 2012, 09:18:42 PM »

- modify lookup method so partial matches can be made.

This is my solution, also extended it so user can enter either uppercase or lowercase and it will still find a partial match.

Code: (Objective-C)
-(AddressCard *) lookup: (NSString *) theName
{
    // lookup entry in addressbook, assume EXACT MATCH
    // use brute force lookup
    for (AddressCard *nextCard in book)
    {
        /*
        if ([nextCard.name caseInsensitiveCompare:theName] == NSOrderedSame) {
            return nextCard;
        }
        */
       
        if ([[nextCard.name lowercaseString] rangeOfString:[theName lowercaseString]].location == NSNotFound) {
            // NSLog(@"string not found!");
        } else {
            return nextCard;
        }
   
    }
    return nil;
}
     
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.