代碼:
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);
這樣就可以了。