views:

23

answers:

2

I have very big unsigned integral number in NSString. This may be big to 2^64. Is there an existing functions/classes parsing this?

As I know, it's unsigned long long value, but, It's hard to know what kind of method should I use to parse this.

A: 

Perhaps not the prettiest answer, but you should be able to do something like this:

#include <stdlib.h>
...
unsigned long long parsedValue = strtoull([yourString UTF8String], NULL, 0);

Someone else might have a more cocoa-ey way of doing it.

Stephen Canon
Oh, this is nice. I like C functions. Thanks for answer!
Eonil
A: 

This might work, though it only gets to 2^63 - 1:

NSScanner *scanner = [NSScanner scannerWithString:numericString];
long long valueFromString;
if(![scanner scanLongLong:&valueFromString]) {
    //ERROR
}

There doesn't appear to be a scanUnsignedLongLong method for NSScanner.

JP
Thanks for answer, but that's just the trouble what I'd explained. The problem is just the value can be up to 2^64.
Eonil