Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memcopy in C#

Status
Not open for further replies.

yfbf

Programmer
Oct 2, 2004
24
BE
I have an array of bytes like :

<B0><00><01><B0><01><03><C0><00><B0><00><01><B0><01><03>

I would like to compare if one byte is in the array ( <C0>) an copy at the index of this byte selected to the end of the array

ex :

Select the <C0> and copy it to another array

<B0><00><01><B0><01><03><C0><00><B0><00><01><B0><01><03>

=> result : <C0><00><B0><00><01><B0><01><03>

Best Regards
 
No need for memcpy -- just write the code to index into the arrays and do the copy. Under .NET, everything is an object.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Yes I know.

Can you write an example ?

Best Regards
 
Something like this:
Code:
// myArray is the array of bytes
// mySearchByte is the byte to search for
// myNewArray is the destination array

int iPos = Array.IndexOf(myArray, mySearchByte);

if (iPos > myArray.GetLowerBound(0)) {
   Byte[] myNewArray = new Byte(myArray.GetUpperBound(0) - iPos);
   // Copy from found byte to end of myArray to myNewArray
   for (i = 0; i < iPos; i++) {
      myNewArray[i] = myArray[iPos + i];
   }
} else {
   // not found in array
}
Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You can perform block copy by using a static method of the System.Buffer class:

public static void BlockCopy(
Array src,
int srcOffset,
Array dst,
int dstOffset,
int count
);

This method is faster than a for loop.
 
Thanks, B00gyeMan

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top