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?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top