Tuesday, May 24, 2011

How to find if NSString has specific characters


 NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ"] invertedSet];
    
    if ([strValue rangeOfCharacterFromSet:set].location == NSNotFound
        NSLog(@"character found");
    else

        NSLog(@"no character found");

Code above will find out whether NSString strValue has characters from set (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ) . You can create your own own characters set with any values like even special characters(? >  etc).

2 comments:

  1. your blogs is awesome.
    Sport Pack
    sms ACT SPO and send it to 50000. And to deactivate the service sms DEACT SPO and send it to 50000
    Charges
    Rs. 7/Week.

    ReplyDelete