How do I get the bytes length of NSString
? if myString
contains "hallo", myString.length
will return 5, but how many actual bytes are taken?
A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.
int len = [myString length];
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With