检测字符串中数字个数:
-(int)numberOfDigits{ int number = 0; for (int i = 0; i < self.length; i++) { unichar c = [self characterAtIndex:i]; if((c > 47)&&(c < 58)) { number++; } } return number; }
检测字符串中特殊符号个数:
-(int)numberOfSpecialCharacter{ NSString *specialCharacters = @"~`!@#$%^&*()_+-=[]|{};':\",.<>?/";//规定的特殊字符,可以自己随意添加 int number = 0; for (int i = 0; i < self.length; i++) { NSString *subStr = [self substringWithRange:NSMakeRange(i, 1)]; if([specialCharacters containsString:subStr]) { number++; } } return number; }