Link to home
Start Free TrialLog in
Avatar of korpiklaani
korpiklaani

asked on

Split byte array

I have to split a byte array on specific bytes.
For example i have a byte array with the bytes 123 456789 123abcdef
i want to split everytime 123 occurs and then save it translated into a string array but i cant find out howto =/ can anyone help me?

thanks

byte[] notsplitted = {0xAB, 0xFE, 0x10, 0x12, 0x13, 0xAB, 0xFE};

byte[] split_at = {0x10, 0x12, 0x13};

//after split it should look like this: 0xAB 0xFE 0xAB 0xFE
//and translated into a string array

Open in new window

Avatar of WesWilson
WesWilson
Flag of United States of America image

I need some clarification.

1. In the example you show, do you want to split at the full sequence (0x10, 0x12, 0x13) or when any of those elements occur?

2. Ultimately, you are looking for multiple strings, split by the specified characters, but not containing those specified characters, correct?
Avatar of korpiklaani
korpiklaani

ASKER

i want to split the array "notsplitted" its like the String.Split() function in visual studio c#.
I just want to use it with a byte array, i want to split a byte array into several pieces everytime "0x10, 0x12, 0x13" occours. For example: ABC DEF ABC when DEF is the delimiter it should look like ABC ABC at the end. Then just translate ABC into a string array (Encoding.ASCII.GetString()) and give back a string array. But thats not that much important right now, the most important part is just to split the bytes because i cant get it working ):

thanks
So the end result should be a single string, right? We are just removing the byte sequence in split_at from the original array?
a string array because there are several byte arrays after splitting
ASKER CERTIFIED SOLUTION
Avatar of WesWilson
WesWilson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it does work i guess but it adds the bytes into a string without translation?
i need it to get translated like 0x61 is 'a'
What if we cast the byte to char? Change line 24 to:

builder.Append((char)notsplitted[i]);

Open in new window

thanks! you are the best!