Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim inputString As String = Clipboard.GetText
' Make sure TextBox1 is multiline and uses
' a non proportional font such as Courier New
' or Lucida Console
TextBox1.Text = ReformatHexString(inputString)
End Sub
Private Function ReformatHexString(input As String) As String
Dim outputBuilder As New System.Text.StringBuilder
' Get rid of spaces and NewLines
input = input.Replace(ControlChars.Cr, "").Replace(ControlChars.Lf, "").Replace(" ", "")
' Take 8 characters at a time
' Make sure not to step past the end of the String
' by using Math.Min(8, input.Length - indx)
For indx = 0 To input.Length - 1 Step 8
outputBuilder.Append(input.Substring(indx, Math.Min(8, input.Length - indx)))
' Alternately add a Space and a NewLine
' after every 8 characters added
If indx Mod 16 = 0 Then outputBuilder.Append(" ") Else outputBuilder.Append(Environment.NewLine)
Next
' Output as a String, losing any white space added
' to the end in the above code, and
' terminate with a NewLine
Return outputBuilder.ToString.TrimEnd & Environment.NewLine
End Function