I have this line of code to convert NSString to NSData:
NSData *data = [NSData dataWithBytes:[message UTF8String] length:[message lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
How do I do this in Unicode instead of UTF8? My message may contain cyrillic characters or diacritical marks.
First off, you should use dataUsingEncoding:
instead of going through UTF8String
. You only use UTF8String
when you need a C string in that encoding.
Then, for “Unicode” (specifically, UTF-16), just pass NSUnicodeStringEncoding
instead of NSUTF8StringEncoding
in your dataUsingEncoding:
message.
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