Pergunta

How can you convert a string value to decimal code point in xCode? What type of encoding can I use to convert these to the correct representation?

Examples:

string: 9 in decimal code point encoding is 57

string: 1 in decimal code point encoding is 49

string: F in decimal code point encoding is 70

Can you give example to how to do this?

Foi útil?

Solução

Get the character value instead of the string value. So instead of string @"F" you want character 'F'. NSLog(@"F = %d",'F');

You can do this with a larger string by using the method characterAtIndex:(NSUInteger) and enumerating over the string.

int encVal = (int)[someString characterAtIndex:0];

Outras dicas

You can do this:

unichar ch = [someString characterAtIndex:0]; // assume the 1st character
int code = (int)ch;

For the string @"9", ch will be the character '9' and code will be the value 57.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top