Search code examples
c#wpfbinary-searchbinary-data

Custom Newline in Binary Stream using Hex Array in WPF


I have a binary file I am reading and printing into a textbox while wrapping at a set point, but it is wrapping at places it shouldn't be. I want to ignore all line feed characters except those I have defined.

There isn't a single Newline byte, rather it seems to be a series of them. I think I found the series of Hex values 00-01-01-0B that seem to correspond with where the line feeds should be.

How do I ignore existing line breaks, and use what I want instead?

This is where I am at:

shortFile = new FileStream(@"tempfile.dat", FileMode.Open, FileAccess.Read);
DisplayArea.Text = "";                
byte[] block = new byte[1000];
shortFile.Position = 0;
while (shortFile.Read(block, 0, 1000) > 0)
{
    string trimmedText =  System.Text.Encoding.Default.GetString(block);
    DisplayArea.Text += trimmedText + "\n";
}

Solution

  • I had just figured it out a couple minutes before dlatikay posted, but really appreciated seeing that he also had the right idea. I just replaced all control characters with spaces.

    for (int i = 0; i < block.Length; i++)
    {
        if (block[i] < 32)
        {
            block[i] = 0x20;
        }
    }