2013-07-18 79 views
1

我有一個字符串,我想要獲取ASCII字節表示形式,然後再添加兩個單個ASCII字節到末尾。將單個字節附加到VB.NET中的字節數組中

要做到這一點,最簡單的方法是什麼?從我使用Google進行搜索時,VB的append方法似乎都只追加字符串和數組,而不是字符或字節......這是這種情況嗎?

例如,

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

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

然後,如果在文本框中輸入「ABC」,陣列應該結束了保持六角41, 42, 43, 04, 0A

回答

3

試試這個

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)) 
+0

感謝您的快速回復! :) – Toby

0

你可以用串聯的兩個值:

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