Zech
Zech

Reputation: 13

Remove Hexa without char in each line

I have data in the form of from TextBox1

00 00 00 4E FF 53 4D 42 25 00 00 00 00 18 01 28  ...N.SMB%......(
00 00 00 00 00 00 00 00 00 00 00 00 00 08 12 8B  ................
01 08 7E 31 11 00 00 05 00 00 00 00 00 00 00 02  ..~1............

and I tried to change it to be like this on the result TextBox2

...N.SMB%......(
................
..~1............

I've tried the function *. remove but only the first row are deleted but the second line and so on are not deleted. Can anybody help me?

i use this code

string test = rtText1.Text;
rtText2.Text = test.Remove(0, 48);

and then this result rtText2

...N.SMB%......(
00 00 00 00 00 00 00 00 00 00 00 00 00 08 12 8B  ................
01 08 7E 31 11 00 00 05 00 00 00 00 00 00 00 02  ..~1............

how can I make a command "test.Remove (0, 48);" can be done on each line? or is there another function?

Upvotes: 1

Views: 74

Answers (2)

Lander
Lander

Reputation: 3437

It looks to me as though you're trying to remove the hexadecimal representation of whatever string is on the right.

This did the trick for me:

// Initial data
string Data = @"00 00 00 4E FF 53 4D 42 25 00 00 00 00 18 01 28  ...N.SMB%......(
00 00 00 00 00 00 00 00 00 00 00 00 00 08 12 8B  ................
01 08 7E 31 11 00 00 05 00 00 00 00 00 00 00 02  ..~1............";
// An array containing each line of data
string[] lines = Data.Split('\n');
Data = "";
// Loop for each line, removing each "byte" + it's space, plus the trailing space
for (int i = 0; i < lines.Length; i++)
{
    Data += lines[i].Remove(0, (3 * 16) + 1);
    if (i != lines.Length - 1)
        Data += "\r\n";
}
Console.Write(Data);

And here is the output:

...N.SMB%......(
................
..~1............

ideone link

Upvotes: 0

JDB
JDB

Reputation: 25810

It's hard to say exactly what you need based on what you've posted, but a regex may work well here:

TextBox2.Text = System.Text.RegularExpressions.Regex.Replace(
                    TextBox1.Text, 
                    @"^.{49}", 
                    "", 
                    RegexOptions.Multiline );

This will simply replace the first 49 characters of each line with an empty string.

Upvotes: 1

Related Questions