I have tried googling it but didn’t got the exact answer as required.
I want to convert a NSString into Byte Array in iPhone.
Also I want to know that Do the result of conversion of NSString to byteArray in iPhone will be same as conversion of string to byteArray in JAVA?
Thanks for your help in advance…
There are many different encodings possible. If you use the same encoding in both Objective-C and in Java, then you should get the same bytes (or string, if you’re going the other way). I’d expect Java to use UTF8, which is specified in Cocoa as
NSUTF8StringEncoding.There are several methods in NSString for converting a string to a pile o’ bytes. Three of them are:
-cStringUsingEncoding:,-UTF8String, and-dataUsingEncoding:. The first returns a char * pointing to a null-terminated array of char. The second does pretty much the same thing as calling the first and specifying UTF8. The third returns a NSData*, and you can access the bytes directly using NSData’s-bytesmethod.