Reputation: 1549
What is the best way to convert from char *
to an instance of NSString
?
I used the method -stringWithUTF8String:
, but it's not good: the result contains "\n" at the end!
Upvotes: 7
Views: 3891
Reputation: 73
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];
Upvotes: 0
Reputation: 124997
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.
Upvotes: 3