Convert from char* to NSString?
What is the best way to convert from char *
to an instance 开发者_开发技巧of NSString
?
-stringWithUTF8String:
, but it's not good: the result contains "\n" at the end!Create the string using the same method you're using now. Then, use a method like -stringByTrimmingCharactersInSet:
to create the trimmed string that you really want.
Here's an actual code example to Convert from char* to NSString, as there was none in the other answer(s). For example with toBeConverted
a char*
:
NSString *convertedValue = [NSString stringWithUTF8String: toBeConverted];
精彩评论