Hi
I use the following to convert std::string to NSString but it return (null) while trying to display the value of the nsstring
I need it to return instead of (null) empty at conversion time any suggestion
StudyDate=[NSString stringWithCString:studyDate length:strlen(studyDate)];
any suggestion to avoid null values
best regards
Edit: The syntax
@"string"is used only for constructing NSString. Withstd::stringyou should use the standard"string"syntax.+stringWithCString:length:has been deprecated since the very early beginning of the iPhone SDK. If the string contains only ASCII characters, often you could use+stringWithUTF8String:instead.Your method works only when
studyDateis a C string (i.e.const char*), but you said you have astd::string. There is no method to directly convert astd::stringinto an NSString. You must use.c_str()to create the C string first:(But the above shouldn’t be the cause you’re getting
(null)because passing astd::stringto+stringWithCString:length:or evenstrlenshould give a compile-time error immediately.So
studyDateshould already be aconst char*. We need more context (code) to see what’s going on.)