NSString str = xxxxx;
[str length];
This code is number of characters.
I want to get number of byte.
NSString str = xxxxx;
[str length];
This code is number of characters.
I want to get number of byte.
NSString
is a unicode string. Thus, there is no such thing as byte length without specifying an encoding for the unicode code points of each letter in the string. As others have pointed out, once you choose an encoding,
-[NSString lengthOfBytesUsingEncoding:]
is what you need.
You might find this what-you-need-to-know tutorial on Unicode helpful.