I wonder which method would be better to convert const char* string to NSString.
I found there are some facts.
But I want to convert with length AND encoding(because I want to make that fine if I have some Non-ASCII character by setting encoding to UTF-8). Any thoughts?
I just think now
But it doesn't work well.
If your const char* variable is named foo
(and it points to a null-terminated string), just say
[NSString stringWithUTF8String:foo]
Because UTF-8 is a superset of ASCII, this will work whether foo
points to UTF-8 or ASCII. Then you can move up to full Unicode with no problems.
Use:
[NSString initWithBytes:length:encoding].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With