c++ - Convert const char* string to NSString with length AND encoding -
I wonder which method would be better to convert the const char * string into NSString.
I found that there are some facts
- [NSString stringWithCString: length:] There is a kind of boycott.
- [NSString stringWithCString: encoding] can be used for my purpose
but I want to convert with length and encoding (because I have a UTF- 8 is OK for some non-ASCII characters by setting the encoding). any idea?
I think now
- Copy the other four and copy it using length std :: strncpy (ch1, ch2, len)
- Usage [NSString stringWithCString: encoding:]
But it does not work well.
If your const char * variable is named foo
(and this is a Pointing to the redundant string), then just say
[NSString stringWithUTF8String: Foo]
Because UTF-8 is a superset of ASCII, it Will work that indicates foo
for UTF-8 or ASCII. You can then go to full Unicode without any problem.
Comments
Post a Comment