I have to read a range of bytes from a byte array. I have the starting position and the ending position to read.
-(NSData *) getSubDataFrom:(int)stPos To:(int)endPos withData:(NSData *) data{
NSRange range = NSMakeRange(stPos, endPos);
return [data subDataWithRage:range];
}
The above code in ObjectiveC reads the range of data(bytes) from a NSData(byteArray). Is there any equivelent method in c# to do the same. or how else we can do this. Please advise!
The difference between bytes() and bytearray() is that bytes() returns an object that cannot be modified, and bytearray() returns an object that can be modified.
Java String getBytes() The Java String getBytes() method encodes the string into a sequence of bytes and stores it in a byte array. Here, string is an object of the String class. The getBytes() method returns a byte array.
you can use the linq method: MyBytes. Reverse() as well as the Array. Reverse() method.
What do you mean by read? Copy a range of bytes into another byte array?
var mainArray = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
var startPos = 5;
var endPos = 10;
var subset = new byte[endPos - startPos + 1];
Array.Copy(mainArray, startPos, subset, 0, endPos - startPos + 1);
From MSDN
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