Frage

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?

War es hilfreich?

Lösung

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];

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top