Hello, I am trying to make something like this:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *myString = @"2c393430 35302c32";
NSLog(@"%@", myString);
const char *utfString = [myString UTF8String];
NSLog(@"%s", utfString);
NSData *data1 = [NSData dataWithBytes:utfString length:strlen(utfString)];
NSLog(@"%@", data1);
[pool drain];
return 0;
}
Outputs:
2009-04-26 06:27:27.606 test[27538:10b] 2c393430 35302c32
2009-04-26 06:27:27.607 test[27538:10b] 2c393430 35302c32
2009-04-26 06:27:27.608 test[27538:10b] <32633339 33343330 20333533 30326333 32>
The data is not the same as the string. I need a way to convert an NSString into an NSData without changing the contents... Or, a way to turn the NSData back into an NSString and restoring it to the original contents of the string. Any help would be great, thanks!
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *myString = @"2c393430 35302c32";
NSLog(@"%@", myString);
const char *utfString = [myString UTF8String];
NSLog(@"%s", utfString);
NSData *data1 = [NSData dataWithBytes:utfString length:strlen(utfString)];
NSLog(@"%@", data1);
[pool drain];
return 0;
}
Outputs:
2009-04-26 06:27:27.606 test[27538:10b] 2c393430 35302c32
2009-04-26 06:27:27.607 test[27538:10b] 2c393430 35302c32
2009-04-26 06:27:27.608 test[27538:10b] <32633339 33343330 20333533 30326333 32>
The data is not the same as the string. I need a way to convert an NSString into an NSData without changing the contents... Or, a way to turn the NSData back into an NSString and restoring it to the original contents of the string. Any help would be great, thanks!