Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i can't seem to get it to save the Hex string back to a file.

This is the code i using to open the file

       Dim builder As New StringBuilder
       Using reader As FileStream = File.OpenRead(Parth)
           Dim length As Long = reader.Length
           Do Until reader.Position = length
               If reader.Position > 0L Then
                   builder.Append(" "c)
               End If
               builder.Append(reader.ReadByte().ToString("X2"))
           Loop
       End Using
       RichTextBox1.Text = builder.ToString()

But how can i save the Hex in richtexbox1.text

Thanks Sutton

  • Leaders
Posted

First, make sure you understand exactly what format the hex needs to be in. Must there be one and only one space between each value? Or can there be more spaces? Tabs? New-lines? And must there be two digits for each value? Or can values less than 0x10 be represented by a single digit? It's easier to write code when you know exactly what it's supposed to do.

 

Assuming that the desired format is that each value be represented as one or two digits with one and only one space between each value, and no other whitespace or other characters, the simplest way to parse the text would be to use the string.split function to split the string into an array of value strings. You can then use the Integer.Parse or Integer.TryParse method to parse each string in the array, and write the value to the file.

 

The problem with this approach is that, if you are dealing with enough data, you'll generate an enormous number of objects for the garbage collector to manage. If you're only dealing with smaller amounts of data, a solution that involves fewer than a dozen lines of code is probably ideal. If you find the performance to be unacceptable, then you can start looking into parsing the numeric values yourself without splitting up the string and calling Integer.Parse.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...