locked
How do you include ASCII characters in a String (.NET 2.0) RRS feed

  • Question

  • I am doing some TCP/IP programming with .NET 2.0 and I have a string that I need to send back to a server. The string must contain 0B (which is the ASCII Vertical Tab) at the beginning. I found http://www.asciitable.com/ and saw that the .NET code was &HB.

    Everytime I try something like:

    Dim iVT As Integer = &HB

    it comes out as "13", but I need it to have the square in the string (or should I say the ASCII 0B value).

    I then tried:

            Dim sACK As String = &HB & "string data"
            Dim bResponse As Byte() = System.Text.Encoding.ASCII.GetBytes(sACK)

            Dim sResponse As String = System.Text.Encoding.ASCII.GetString(bResponse)

    Still every time I print it to the screen I get "13". The Server I am sending the data will only respond to the ASCII (not 13). I have never tried using ASCII encoding, but figure it can't be that difficult once I see the right method of how to do it. Anyone know how to do this? Will I need to use StringBuilder?

    Wednesday, April 25, 2012 11:10 PM

Answers

  • Dim sACK As String = ChrW(&HB) & "string data"

    • Proposed as answer by Mike Feng Thursday, April 26, 2012 9:57 AM
    • Marked as answer by Mike Feng Tuesday, May 8, 2012 11:59 AM
    Thursday, April 26, 2012 12:58 AM