Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSString to char array [duplicate]

const char arr[]="Hello There";

I am trying to create a character array as above.

Below, is the code which I use. Is this a correct way to create a char array.

-(void) createCharArray:(NSString*) text{
   char arr[text.length];
   for(int i=0;i<text.length;i++){
    arr[i]=[text characterAtIndex:i];
   }
}

Do we have to worry about null termination? Do we have any other way to achieve the same?

like image 507
NNikN Avatar asked Feb 19 '14 02:02

NNikN


1 Answers

You can use UTF8String. Eg: [myString UTF8String].

like image 62
Pranav Avatar answered Oct 01 '22 01:10

Pranav