Removing chars per index in a char array

hello guys

how could i remove certain parts of a char array ?

like i have a

char InitialChar[20];

ho can i remove first and last slice so it becomes a new char or resize to itself containg all but first and last?
char clean[18]

or is there a way to delete per index like in the this StringDelete(string &sDest, const int nIndex, const int nSize)

or similar ?

cheers

Well one way would be to shift the elements.

for(byte d = 0; d < 20; d++)
{
Array[d] = Array[d+1];
}

This will shift out the first element, and you use an IF statement, to add a NULL or 0 in the last element.

Or.

The other way would be to simply copy the elements of the Array to a new one, starting at the second element and stop before it gets to the last element.

In the context of your other thread, you don't need to. You can simply adjust your packet parsing code to start at packetBuffer[1] instead of packetBuffer[0] . Removing them is more trouble than it's worth in this case.

hi HazardsMind and wildbill

thank you for your replies .

yes i was thinking something like this but i thought maybe there was an arduino or C function for this cases ?.

if i do start at packetBuffer[1] instead of packetBuffer[0] is fine but , i need to assign the whole loop to a function so for the start i guess i can do i+1 and to get rid of the last one i guess do the loop (i-1)++. just wanted to clean it as much as possible for further easy logic.

;D

char someBuffer[20];
char subBuffer[18];

...

memcpy(subBuffer,someBuffer+1,18);

That will copy 18 bytes into subBuffer[] starting from someBuffer[1]

If you want to just shift your starting point, you can just do this:

char packetBuffer[20];
char* ptr = packetBuffer + 1;
ptr[0] = whatever; //set packetBuffer[1] = whatever

Then in you can access packetBuffer[1] as ptr[0] and so on.

hi cool , i,ll try it also.

i got it working like that thank you

char CleanBuffer [packetSize-HeaderEndSize];
memcpy(CleanBuffer,packetBuffer+HeaderSize,packetSize-HeaderEndSize);