What is the length in bytes of a NSString? What is the length in bytes of a NSString? ios ios

What is the length in bytes of a NSString?


NSString *test=@"ABCDEFGHIJKLMNOPQRSTUVWXYZ";NSUInteger bytes = [test lengthOfBytesUsingEncoding:NSUTF8StringEncoding];NSLog(@"%i bytes", bytes);


To get the bytes use

NSData *bytes = [string dataUsingEncoding:NSUTF8StringEncoding];

Then you can check bytes.length

Number of bytes depend on the string encoding


Well:

NSString* string= @"myString";NSData* data=[string dataUsingEncoding:NSUTF8StringEncoding];NSUInteger myLength = data.length;


matomo