删除UItextField的起始0

代码:

NSString *tempStr = self.consumerNumber.text;        

if ([tempStr hasPrefix:@"0"] && [tempStr length] > 1) {
    tempStr = [tempStr substringFromIndex:1];

    [self.consumerNumbers addObject:tempStr];>           
}

输出:001600240321

期望输出:1600240321

谢谢!

NSString *stringWithZeroes = @"001600240321";

NSString *cleanedString = [stringWithZeroes stringByReplacingOccurrencesOfString:@"^0+" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, stringWithZeroes.length)];

 NSLog(@"Clean String %@",cleanedString);

这样就可以了。

NSString *str=@"001600240321";
str=[str stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0"]]
NSLog(@"%@",str);