2

I have a string that I'd like to get the ASCII byte representation of, then add two more single ASCII bytes to the end of.

What is the simplest way to do this? From my searching using Google, it seems that VB's append methods all append only strings and arrays, not characters or bytes... Is this the case?

For example,

Dim byte1 As Byte = &H4
Dim byte2 As Byte = &HA

Dim array() As Byte = Encoding.ASCII.GetBytes(MyTextBox.Text) + byte1 + byte2

Then if "ABC" is entered in the text box, the array should end up holding hex 41, 42, 43, 04, 0A.

2 Answers 2

3

Try this

    Dim byte1 As Byte = &H4
    Dim byte2 As Byte = &HA

    Dim array() As Byte = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text & Chr(byte1) & Chr(byte2))
Sign up to request clarification or add additional context in comments.

Comments

0

You can concatenate the two values with:

Dim array() as Byte = {byte1, byte2} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.