iOS 字符和数字一起算起总共位数

NSString *numPattern=@"[\u4e00-\u9fa5]"; //玄机^$

    NSError *error = [NSError new];

    

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:numPattern options:NSRegularExpressionCaseInsensitive error:&error ];

    

    NSInteger testCount = [regex numberOfMatchesInString:self.userName_field.text options:NSRegularExpressionCaseInsensitive range:NSMakeRange(0, [self.userName_field.text length])];

  

    

    if (testCount > 0) {

        NSMutableString *mutableContent = [NSMutableString stringWithString:self.userName_field.text];

        [regex replaceMatchesInString:mutableContent options:NSRegularExpressionCaseInsensitive range:NSMakeRange(0, [self.userName_field.text length]) withTemplate:@"**"];

        NSLog(@"before replace:%@nafter replace:%@",self.userName_field.text,mutableContent);

        

        NSLog(@"mutableContent = %d ", [mutableContent length]);

    }


你可能感兴趣的:(iOS 字符和数字一起算起总共位数)