2010-07-31 8 views
5

necesito escribir números como: 1> yekconvertir a las palabras, en el objetivo c

123> yeksad o bist o se

1123> yek Hezar o yeksad o bist o se

3002001> se milones o ¿Hezar o yek ...

I, m principiante en Objective C :)

lo escribo en C pero quiero convertir ¡en obj_c! ¿Cómo puedo hacer eso?

algo como:

const char *yekan[10]={"","yek","do","se","chahar","panj","shesh","haft","hasht","noh"}; 
char ary[9]={'0','0','0','0','0','0','0','0','0'}; 

// get a number from user & converting it to string 

// user number: 123 > the number in ary:000 000 123) 

// '3' => 3 

m=(int) ary[8]; 
m=m-'0'; 

if (j==3) { printf(" %s ",yekan[m]);} // yekan[3] = se 

output: se 

gracias.

Respuesta

21

clase NSNumberFormatter ha incorporado en la funcionalidad de los números de conversión de palabras:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
[formatter setNumberStyle: NSNumberFormatterSpellOutStyle]; 
[formatter setLocale:...]; // Set locale if you want to use something other then the current one 
NSString* numberString = [formatter stringFromNumber:[NSNumber numberWithInt: 100]]; 
+0

gracias por su respuesta :), pero ¿Cómo puedo configurar el entorno local en Persa ...? – aden

+0

Wo0oW puedo establecer persianlocal :) NSLocale * persianLocale = [[NSLocale alloc] initWithLocaleIdentifier: @ "fa_IR"]; gracias de nuevo: * – aden

+0

Muchas gracias :) –

0

versión de Swift respuesta @Vladimir (Por si acaso)

let formatter = NSNumberFormatter() 
formatter.numberStyle = .SpellOutStyle 
formatter.locale = NSLocale(localeIdentifier: "en_US") 
let string = formatter.stringFromNumber(55015515) 
Cuestiones relacionadas