Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub ButtonConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonConvert.Click
- Dim text As String = TextBoxInput.Text
- If text.Length > 0 Then
- Dim array As Byte() = StringToArray(text)
- If array IsNot Nothing Then
- TextBoxOutput.Text = System.Text.Encoding.Unicode.GetString(array)
- End If
- End If
- End Sub
- Private Function StringToArray(ByVal text As String) As Byte()
- Dim errorText As String = Nothing
- If text IsNot Nothing Then
- text = text.Replace(" ", Nothing).Trim()
- Dim textLength As Integer = text.Length
- If textLength Mod 2 = 0 Then
- textLength /= 2
- Dim array(textLength - 1) As Byte
- Dim byteCounter As Integer = 0
- Try
- For byteCounter = 0 To textLength - 1
- array(byteCounter) = Convert.ToByte(text.Substring(byteCounter * 2, 2), 16)
- Next
- Return array
- Catch ex As Exception
- byteCounter += 1
- errorText = "An error occured while translating the " & byteCounter & IIf(byteCounter = 1, "st", IIf(byteCounter = 2, "nd", IIf(byteCounter = 3, "rd", "th"))) & " Byte."
- End Try
- Else
- errorText = "Input is mal-formatted"
- End If
- Else
- errorText = "No input has been defined!"
- End If
- If errorText IsNot Nothing Then
- MessageBox.Show(errorText, "Parsing-Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End If
- Return Nothing
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement