NSString *str = @"001600240321";
NSString *newStr = [@([str integerValue]) stringValue];
If the NSString
contains numbers only.
Other wise use this:
-(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;
}
Simply call this method:-
NSString *stringWithZeroes = @"0000000016909tthghfghf";
NSLog(@"%@", [self stringByRemovingStartingZeros:stringWithZeroes]);
OutPut: 16909tthghfghf