How do you convert from NSString
to UInt64
?
For example, something like this if a UInt64Value
helper method existed:
NSString *value = @"1234567";
UInt64 convertedValue = [value UInt64Value];
I am trying to do this in an iOS project.
To pitch another possibility for completeness:
NSScanner *scanner = [NSScanner scannerWithString:value];
unsigned long long convertedValue = 0;
[scanner scanUnsignedLongLong:&convertedValue];
return convertedValue;
... check the result on scanUnsignedLongLong
if you want to differentiate between finding a value of 0 and finding something that isn't a number.
NSString * num = @"123456";
NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc]init];
NSNumber * number = [numberFormatter numberFromString:num];
unsigned long long valueUInt64 = number.unsignedLongLongValue;
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