Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Check if the entered text uses only English letters

NSCharacterSet* tSet = [NSCharacterSet characterSetWithCharactersInString:
               @"abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"];
    NSCharacterSet* invSet = [tSet invertedSet];
    NSString* legalS = @"abcdA1";
    NSString* illegalS = @"asvéq1";

    if ([legalS rangeOfCharacterFromSet:invSet].location != NSNotFound)
        NSLog(legalS); // not printed

    if ([illegalS rangeOfCharacterFromSet:invSet].location != NSNotFound)
        NSLog(illegalS); // printed

Sort Array

NSArray *myArray = [myArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

or

NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:lastNameDescriptor]];