Convert NSString into char array

Viewed 91304

I have a variable of type char[] and I want to copy NSString value in it. How can I convert an NSString to a char array?

6 Answers

Rather than getCharacters:range:, I use:

[stringToCopy getCString:c_buffer maxLength:c_buffer_length encoding:NSUTF8StringEncoding];

The result is a char[] (instead of unichar[]), which is what the OP was wanting, and what you probably want to use for C compatibility.

Related