ios截取NSString中字母数字

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
       
        NSString *isNumberOrLetter = [headName substringToIndex:26];
        NSString * later = [headName substringWithRange:NSMakeRange(25, 1)];
       
        NSString *names = [isNumberOrLetter stringByReplacingOccurrencesOfString:@"[^0-9,a-z]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [isNumberOrLetter length])];
       
        NSString *laterNames = [later stringByReplacingOccurrencesOfString:@"[^0-9,a-z]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [later length])];
       
        int *nameLength = 0;
       
        int nameCount = 0;
       
        NSLog(@"%d",nameCount);
       
        if (names.length > 0) {
            for (int i = 1; i < names.length; i++) {
                ++i;
                nameCount = i;
                NSLog(@"%d",nameCount);
            }
            nameLength = nameCount / 2 + 25;
        }
        else{
            nameLength = 25;
        }
       
        if (laterNames.length == 0) {
            nameLength = nameLength + 1;
        }
       
        int *headNameLength = headName.length;
       
        if (headNameLength > nameLength) {
            NSLog(@"%d",headName.length);
            headName = [headName substringToIndex:nameLength];
            NSLog(@"%@",headName);
            headName = [headName stringByAppendingString:@"..."];
        }
    }

你可能感兴趣的:(NSString)