How do I extract a single byte from within a string on iPhone?
In Android, I can extract a single byte from within a string using code like the following:
byte[] arrByte = String.get开发者_JAVA百科Bytes(); .
If I wanted to do this on the iPhone in Objective-C, how could I accomplish the same task? Additionally, how could I get a byte for a given index in the string?
If you take a look at the NSString
reference you will get various methods to get the data from a string. An example is
NSData *bytes = [yourString dataUsingEncoding:NSUTF8StringEncoding];
You can also make use of the method UTF8String
精彩评论