Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert NSString to bytes

Tags:

nsstring

NSString *test = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

How to convert this string to bytes?

like image 359
Raju Avatar asked May 19 '09 08:05

Raju


2 Answers

NSData *bytes = [test dataUsingEncoding:NSUTF8StringEncoding];
like image 102
Chuck Avatar answered Oct 23 '22 04:10

Chuck


Do you want something like this:

NSString *test=@"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSUInteger bytes = [test lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%i bytes", bytes);
like image 32
Jens Kohl Avatar answered Oct 23 '22 04:10

Jens Kohl