Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSString to Unsigned long

Tags:

ios

nsstring

I am having NSString value which I want to convert in unsigned long. I used code below

NSString *updateId = [NSString stringWithFormat:@"%@",[tweet updateId]];

NSLog(@"%@",[tweet updateId]);
unsigned long  tweetId = [updateId longLongValue];
NSLog(@"ButtonPressed: .......%llu",tweetId);

But it is not returning correct value...

like image 839
Abhishek Avatar asked May 03 '11 07:05

Abhishek


1 Answers

The Cocoa way would be to use [NSNumberFormater]1:

NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
NSLog(@"%lu", [[formatter numberFromString:updateId] unsignedLongValue]);
[formatter release];

What's the the type of [tweet updateId]?
Does it contain any localization (e.g. thousand separators)?
If so, you could configure the NSNumberFormatter instance with setLocale:

like image 161
Thomas Zoechling Avatar answered Nov 15 '22 04:11

Thomas Zoechling