我试图将文本框中的文本保存为字节。例如,Textbox1中的文本是" 00001E0403"我想将它们保存为字节。那我该怎么办?
答案 0 :(得分:1)
您可以保存为字节数组。尝试使用此命令:
System.Text.Encoding.Unicode.GetBytes(textbox1.text)
答案 1 :(得分:0)
试试这个:
Imports System.Globalization
Private Sub GetBytes()
Dim l As Integer = TextBox1.Text.Length - 1
Dim dataIndex As Integer = 0
Dim data(l \ 2) As Byte
For i As Integer = 0 To l Step 2
Dim hexChars As String = TextBox1.Text.Substring(i, Math.Min(2, TextBox1.Text.Length - i))
Dim dataByte As Byte
Byte.TryParse(hexChars, NumberStyles.HexNumber, Nothing, dataByte)
data(dataIndex) = dataByte
dataIndex += 1
Next i
End Sub