One more modification (remove spaces):
and this code works. But the point is, printable ASCII characters are in the range 32-127, and some of your sample hex values are outside of this range. The code above should check if the hex value is not a printable ASCII it outputs, lets say a dot (.) character. Like this:Code:Dim hex As String = TextBox1.Text Dim hexNumber As Integer Dim i As Integer For Each line As String In TextBox1.Lines line = Replace(line, Chr(32), String.Empty) For i = 0 To line.Length - 1 Step 2 hexNumber = Convert.ToInt32(line.Substring(i, 2), 16) TextBox2.AppendText(Chr(hexNumber)) Next i TextBox2.AppendText(vbCrLf) Next
Code:Dim hex As String = TextBox1.Text Dim hexNumber As Integer Dim i As Integer For Each line As String In TextBox1.Lines line = Replace(line, Chr(32), String.Empty) For i = 0 To line.Length - 1 Step 2 hexNumber = Convert.ToInt32(line.Substring(i, 2), 16) If hexNumber >= 32 AndAlso hexNumber <= 127 Then TextBox2.AppendText(Chr(hexNumber)) Else TextBox2.AppendText(".") End If Next i TextBox2.AppendText(vbCrLf) NextI copy pasted those 14 lines in to my test code and got out 14 lines. Check your line break characters. Some lines may have vbCr or vbLf instead of vbCrLf. If the original content comes from a file this may well be the case.If you copy and past this into textbox1 then textbox2 will have 6 lines, instead of 14.
Teme @ windevblog.blogspot.com




Reply With Quote