' VB.Net 把byte array轉成String
Dim b As Byte() = {65, 66, 67, 68, 69, 70, 71}
Dim str As String
Dim enc As New System.Text.ASCIIEncoding()
Response.Write(enc.GetString(b))
' VB.Net 把String 轉成byte array
Dim encAs New System.Text.ASCIIEncoding()
Dim b As Byte() = enc.GetBytes("ABCDEFG")
For i As Integer = 0 To b.Length - 1
Response.Write(b(i).ToString()+",")
Next
' 將字串轉成byte陣列
Shared Function StrToByteArray(ByVal str As String) As Byte()
Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetBytes(str)
End Function
' 將byte陣列轉成字串
Shared Function ByteArrayToStr(ByVal bt As Byte()) As String
Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetString(bt)
End Function

不好意思 打擾了 最近在學習使用 vb.net 與 plc qj71c24c rs232 模組做通訊 目前遇到幾個問題 是否可以指導一下方法 謝謝 通訊方式 2. ENQ + 資料長度 + 資料內容 + Checksumhttp &H05 + 000Ch +"123456789A" + Checksum -> 0ch,00h -> L H (00H) (OcH) 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 資料長度需要使用2位元二進制來表示 可否幫我想想該如何寫
to jason: 您說的資料長度需要用2位元二進制來表示 意思是把123456789A…算出長度轉成二進制嗎?