NSString *str = @"001600240321";
NSString *newStr = [@([str integerValue]) stringValue];
如果NSString
仅包含数字。其他明智的使用这个:
-(NSString *)stringByRemovingStartingZeros:(NSString *)string
{
NSString *newString = string;
NSInteger count = 0;
for(int i=0; i<[string length]; i++)
{
if([[NSString stringWithFormat:@"%c",[string characterAtIndex:i]] isEqualToString:@"0"])
{
newString = [newString stringByReplacingCharactersInRange:NSMakeRange(i-count, 1) withString:@""];
count++;
}
else
{
break;
}
}
return newString;
}
只需调用此方法:-
NSString *stringWithZeroes = @"0000000016909tthghfghf";
NSLog(@"%@", [self stringByRemovingStartingZeros:stringWithZeroes]);
输出:16909tthghfghf