2010-07-12 4 views

Répondre

2

vous pouvez essayer (code non testé)

NSString *field = @"s"; 

unichar c = [field characterAtIndex:0]; 
NSLog(@"decimal char %d", c); 

et vice versa

unichar asciiChar = 65; // the character A; can also be written like 'A' or 0x0041 
NSString *stringWithAsciiChar = [NSString stringWithCharacters:&asciiChar length:1]; 

espère que cela aide

ce qui a trait

+0

Wow! Merci beaucoup! Réponse parfaite, vraiment! – Cashew

+1

Bien qu'habituellement correct, cela ne fonctionne pas très bien avec les langages multi-octets (codages UTF16 et supérieurs). –

1

Vous pouvez obtenir le caractère à un certain indice en utilisant le NSStringcharacterAtIndex. Le résultat est un unichar qui est un unsigned short. Vous pouvez probablement utiliser ceci comme valeur ASCII en castant, bien que ce soit un caractère unicode.

Questions connexes