Results 1 to 2 of 2

Thread: ASCII to Hex

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    35

    ASCII to Hex

    I'm currently using the following code, but it won't convert "advanced ASCII", such as: ™ ¥ © etc...
    It just gives them a question mark value (3F).

    How can I make it convert them correctly?

    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
            TextBox2.AppendText((hexn.ToString()))

  2. #2

    Re: ASCII to Hex

    Quote Originally Posted by MS-47 View Post
    I'm currently using the following code, but it won't convert "advanced ASCII", such as: ™ ¥ © etc...
    It just gives them a question mark value (3F).

    How can I make it convert them correctly?

    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
            TextBox2.AppendText((hexn.ToString()))
    ...because they're not ASCII; change encoding to UTF-8 instead or Unicode.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width