开发者

Convert from char* to NSString?

开发者 https://www.devze.com 2023-03-12 16:06 出处:网络
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!Create the s

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!


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消