开发者

How do I extract a single byte from within a string on iPhone?

开发者 https://www.devze.com 2023-04-05 01:01 出处:网络
In Android, I can extract a single byte from within a string using code like the following: byte[] arrByte = String.get开发者_JAVA百科Bytes(); .

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

0

精彩评论

暂无评论...
验证码 换一张
取 消