Search code examples
iosobjective-cencodingdecimal-point

How to convert string to UTF-8 Decimal in iOS


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?


Solution

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