Showing posts with label find specific characters in NSString. Show all posts
Showing posts with label find specific characters in NSString. Show all posts

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).