How to covert std::string to NSString? ,why the result is garbled?I use lldb command po
,look at the console ,the red arrow,the _data
display correct string?Why?
std::string resultString = getResult();
NSString *str= [NSString stringWithCString:resultString.c_str() encoding:NSUTF8StringEncoding];
but the str is garbled,like
May be here issue is with string encoding. I have done little test on this input string and found some result on that.
Here I have use complex string
"\x18\xa4\tp\x01"
which you shown in your log. From the result I conclude thatNSUTF8StringEncoding
encoding string is not working with above string.Here is code:
And a reference image for log:
Here you can see that
NSUTF8StringEncoding
returnsnil
string and other encoding gives a result. I'm not sure which encoding scheme is valid for your string. If we know that encoding scheme forresultString
string then we can get more accurate result here.