|
-
Feb 16th, 2013, 10:21 AM
#1
Thread Starter
Member
Textbox text format
When I copy a bunch of bytes out of a hex editor, the format is the following:
Code:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 etc...
I want the format to be like the following:
Code:
00000000 00000000
00000000 00000000
00000000 00000000
etc...
What code should I use?
-
Feb 16th, 2013, 12:12 PM
#2
Re: Textbox text format
What do you mean by copy? Using the clipboard, redirecting output, some other esoteric method?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Feb 16th, 2013, 08:45 PM
#3
Thread Starter
Member
Re: Textbox text format
In HxD, one side shows hexadecimal and the other shows ASCII. When I copy a bunch of bytes from the hex side, and paste them in a notepad for example, they're like in the post above.
-
Feb 17th, 2013, 08:03 AM
#4
Thread Starter
Member
-
Feb 17th, 2013, 10:12 AM
#5
Re: Textbox text format
Assuming you have your copied data assigned to a string variable, you could strip out all the white space (space characters and line terminator characters) from that string, and then build a new string by inserting a space after 8 characters, then a NewLine after another 8 characters and repeating till the end of the string.
Using a StringBuilder for the sake of efficiency:
vb.net Code:
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
Last edited by Inferrd; Feb 17th, 2013 at 10:16 AM.
-
Feb 17th, 2013, 10:20 AM
#6
Thread Starter
Member
Re: Textbox text format
Oh, man, you are a legend! Thank you so much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|