1

I have cpp const char* string which contains "πŸ’•πŸ˜€πŸ˜ playlist" characters. I am trying to convert it into NSString and I am getting "@(NULL)" string.

Following are my steps to convert it.

 string cppString = "πŸ’•πŸ˜€πŸ˜ playlist"; //Cpp data type 
  1. I have one method where I am passing my cpp string like

NSString *str = [self charStringToString:cppString.c_str()];

and the method returns NSString object after some operations:

+ (NSString *)charStringToString:(const char*)cppStringConst { if ( cppStringConst == NULL || cppStringConst == nullptr ) { return @""; } NSString *outputString = [NSString stringWithFormat:@"%@", [NSString stringWithUTF8String:cppStringConst]]; if ( [outputString isEqualToString:@"(null)"] == YES ) { //it should not come here if I am passing πŸ’•πŸ˜€πŸ˜ playlist return @""; } return outputString; } 

Could anyone resolve my problem??

4
  • This does not look like C code at all...possibly tagged incorrectly? Commented Dec 8, 2017 at 11:24
  • Yes @ChrisTunner, I am trying to convert Cpp code(String) into Objective-C. Commented Dec 8, 2017 at 11:26
  • Are you sure that your cppString contains a valid UTF8 encoding? Commented Dec 8, 2017 at 13:03
  • What encoding is your file set to in Xcode? Commented Dec 8, 2017 at 17:56

1 Answer 1

0

Take a look at this answer to a similar question. I'm suspicious of the encoding being used in your const char * string.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.