These are some conversions which an objective C developer often needs while writing code.
NSString to Char * -
NSString *testString = @"Testing";
char *testCharP;testCharP = (char*)[testString cStringUsingEncoding:NSUTF8StringEncoding];
Char * to NSString -
const char *testCharP = "Testing";
NSString *testString;
testString = [NSString stringWithUTF8String:testCharP];
NSData to NSString -
NSString* Str = [[NSString alloc] initWithData:tempData
encoding:NSUTF8StringEncoding];
if data is NULL terminated -
NSString* Str = [NSString stringWithUTF8String:[tempData bytes]];
No comments:
Post a Comment