2011-05-03 36 views
6

Estoy teniendo NSString valor que quiero convertir en unsigned long. Solía ​​código de abajoConvertir NSString a Largo sin signo

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

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

Pero no devuelve valor correcto ...

+0

¿Qué volver? ¿Y cuál es el tipo de datos devuelto por updatedId? – Macmade

+0

updateId está devolviendo NSstring .. Y mi salida es 65278530740695040 2011-05-03 12: 47: 56.704 MiniTwit [2949: 207] ButtonPressed: ....... 6071468025620606976 – Abhishek

+0

Para solicitar soporte para la lectura de valores sin signo de NSString, por favor visite http://bugreport.apple.com y archive una trampa de radar: // 2264733 contra el componente 'Fundación | X'. –

Respuesta

11

La forma cacao sería utilizar [NSNumberFormater]1:

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

Cuál es el tipo de [piar UpdateID]?
¿Contiene alguna localización (por ejemplo, miles de separadores)?
Si es así, podría configurar la instancia NSNumberFormatter con setLocale:

+0

[tweet updateid] es del tipo NSString – Abhishek

+0

NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init]; \t NSLog (@ "% lu", [[formatter numberFromString: updateId] unsignedLongValue]); [_engine deleteUpdate: formatter]; [release del formateador]; no funciona dando advertencia – Abhishek

+1

¿Por qué lo envuelve en otro NSString entonces? Puede pasar directamente [tweet updateId] a numberFromString:. –

0

Usted puede tratar de la función de la atol stdlib C:

unsigned long tweetId = atol([ updateId cStringUsingEncoding: NSASCIIStringEncoding ]); 

Y, por cierto, su NSLog debe ser lu, no llu.

+0

lu también devuelve un valor incorrecto – Abhishek

+0

¿Has probado con atol? – Macmade

+0

¿Qué archivo de encabezado debo incluir? Está dando advertencia NSString puede no responder a CStringUsingEncoding – Abhishek

0
unsigned long tweetId = [[NSNumber numberWithInteger:[updateId integerValue]] unsignedLongValue]; 
Cuestiones relacionadas