hungbm06
hungbm06

Reputation: 1549

Convert from char* to NSString?

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

Answers (2)

Théophane
Théophane

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

Caleb
Caleb

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

Related Questions