I need to remove the first character from my UITextfield
if it's a 0.
Unfortunately I don't know how to extract the value of the first character or extract the characters of the string after the first character.
Thanks
One solution could be:
if ([string hasPrefix:@"0"] && [string length] > 1) { string = [string substringFromIndex:1]; }
You would probably want something like this, using hasPrefix:
if ([string hasPrefix:@"0"]) { string = [string substringFromIndex:1]; }
You could also use characterAtIndex: which returns a unichar:
if ([string characterAtIndex:0] == '0') { string = [string substringFromIndex:1]; }
Note that, 'a' is character, "a" is C string and @"a" is NSString. They all are different types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With