[ACCEPTED]-Convert const char* string to NSString with length AND encoding-objective-c++

Accepted answer
Score: 45

If your const char* variable is named foo (and 5 it points to a null-terminated string), just 4 say

[NSString stringWithUTF8String:foo]

Because UTF-8 is a superset of ASCII, this 3 will work whether foo points to UTF-8 or ASCII. Then 2 you can move up to full Unicode with no 1 problems.

Score: 17

Use:

[NSString initWithBytes:length:encoding].

0

More Related questions