Hexademical to String

Posts 1–4 of 4 · Page 1 of 1
Hexademical to String
Ok well..

I want my Richtextbox1.Text to be converted from hex numbers to a readable string...

Richtextbox1.text should be converted on button1 click event.

e.g....

From
Code:
286974656D09286E616D65203
To
Code:
(item	(name
so are you trying to encrypt something?

maybe you could try something like this.. would take forever though.

If textbox.text = "1" then
textbox.text = "a"
end if

thats just an idea.. would take forever though, so its not a good way to do it.
I am writing a tut, Ill post it here, I have asked Blubb to add pictures and make it a tut for the VB section.


Here is the TUT

Convert Hex To String and back to Hex.

  • As Always Open Visual Basic .NET and follow along
  • Add a textbox, Label and 2 buttons to your form


  1. Button1 Text = "To Hex"
  2. Button2 Text = "To String"


  • Double Click Button One and add this code


Code:
 Dim str As String = TextBox1.Text
        Dim bytes() As Byte
        Dim hexn As System.Text.StringBuilder = New System.Text.StringBuilder

        bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

        For i As Integer = 0 To bytes.Length - 1
            hexn.Append(bytes(i).ToString("x"))
        Next

        Label1.Text = (hexN.ToString())
This code converts the text in textbox one to hex

  • Double Click Button two and add this code


Code:
Dim S As String = TextBox1.Text
        Dim EM As String = ""
        Dim i As Integer
        For i = 0 To S.Length - 2 Step 2
            EM = EM & Chr(CInt("&H" & S.Substring(i, 2)))
        Next
        Label1.Text = EM
Note: You are going to want to handle errors, If you input a string and try to convert it to a string it will error, so be sure you add error handling.

This Code converts the text in textbox1 and converts it to a string

Hope This Helps
/wants to marry you
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us