سؤال

i am trying to remove zero "0" from left in the string means if string is "0000560352" 

it will give it to me "560352". it's dynamically change so if user will enter in textbox like "0560352" then only first zero will remove from string.any idea for this thing.

هل كانت مفيدة؟

المحلول

It is too simple just convert it to NSInteger and then bring back to NSString

NSString *str = @"0000560352";
NSInteger i = [str integerValue];
str = [NSString stringWithFormat:@"%d",i];

نصائح أخرى

You do not need a loop or a conversion

NSCharacterSet *zeros = [NSCharacterSet characterSetWithCharactersInString:@"0"];
NSString *nonLeadingZerosString = [@"000560352" stringByTrimmingCharactersInSet:zeros];

But at the end of the day you want to use a number formatter.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top