Search code examples
objective-cnsstringcstring

NSMutableString to char *


Hot can I convert an NSMutableString to char *?

e.g.

NSString* someval = @"This is a test.";
NSMutableString *temp = [NSMutableSTring stringWithString:someval];
char * temp2 = ????Not sure what to do here???;

Solution

  • Use the -UTF8String method:

    NSString* someval = @"This is a test.";
    NSMutableString *temp = [NSMutableString stringWithString:someval];
    const char * temp2 = [temp UTF8String];