Mika,
I have created two functions of my own which will be better for you. The
zipped project is also attached if you want to download it. Otherwise,
follow thses instructions:
1) Create a new Windows application
2) Add a button
3) Add this import:
Imports System.text
4) Now, paste in the following functions:
Private Function EncodeHexString(ByVal sText As String) As String
Dim intLength As Integer = sText.Length
If (intLength = 0) Then Return ""
Dim intCount As Integer = 0
Dim sb As New StringBuilder(intLength * 2)
Dim bBytes() As Byte = System.Text.Encoding.ASCII.GetBytes(sText)
For intCount = 0 To bBytes.Length - 1
sb.AppendFormat("{0:X2}", bBytes(intCount))
Next
Return sb.ToString()
End Function
Private Function DecodeHexString(ByVal sText As String) As String
Dim intLength As Integer = sText.Length
If (intLength = 0) Then Return ""
Dim intCount As Integer = 0
Dim sb As New StringBuilder(CType(intLength / 2, Integer))
Try
For intCount = 0 To sText.Length - 1 Step 2
sb.Append(Convert.ToChar(Byte.Parse(sText.Substring(intCount,
2), Globalization.NumberStyles.HexNumber)))
Next
Catch ex As Exception
Return ""
End Try
Return sb.ToString()
End Function
5) Double-click button1 & paste in this code:
Dim strMika As String = "Mika"
Dim strEncodedMika As String = EncodeHexString(strMika)
MessageBox.Show(strEncodedMika)
Dim strDecodedMika As String = DecodeHexString(strEncodedMika)
MessageBox.Show(strDecodedMika)
I hope this helps
Crouchie1998
BA (HONS) MCP MCSE
|