Convert NSString into char array

后端 未结 6 1632
别那么骄傲
别那么骄傲 2020-11-29 22:53

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条回答
  •  孤独总比滥情好
    2020-11-29 23:37

    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.

提交回复
热议问题