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??

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sarat Patel
  • 856
  • 13
  • 32

1 Answers1

0

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

Craig
  • 3,253
  • 5
  • 29
  • 43