0

I want to convert NSString to unsigned char type array, I have searched many things but have not found a way to do it, can someone suggest me? ex: input : 16 output: 0x01, 0x06

The input has only the characters of hexa code. I am newly for this objective C and cocoa application so please help on this. Thanks!

KiDo Ruan
  • 1
  • 1

2 Answers2

0

const char* array = [string UTF8String];

This will give you a pointer to the null-terminated array with UTF8 representation of the string.

Davyd Geyl
  • 4,578
  • 1
  • 28
  • 35
-1

Loop the characters in the string and then you can do what you want with them, e.g. print or calc or whatever. I'm sure there are samples of this lying around.

// s is the string ...
for ( NSUInteger i = 0; i < s.length; i ++ )
{
  unichar c = [s characterAtIndex:i];

  // ... do something with c
}
skaak
  • 2,988
  • 1
  • 8
  • 16