- String转Byte()
- Byte()转String
在TCP/IP通信中,客户端与服务端之间传输的数据是以字节流形式,而我们通常在GUI中操控的是字符串。这就需要在发送数据的时候完成字符串到字节数组的转换,同样,在接收数据的时候完成字节数组到字符串的转换。
这项功能可以通过System.Text.Encoding类实现 String转Byte()
Dim str As String = "hello worls" dim bys() As Byte bys = System.Text.Encoding.UTF8.GetBytes(str.Trim) '.Trim 去除首尾的空格Byte()转String
Dim str2 As String str2 = System.Text.Encoding.UTF8.GetString(bys) '或者使用 System.Text.Encoding.UTF8.GetString(rBuffer, offset, length) str2 =System.Text.Encoding.UTF8.GetString(bys, 0, bys.Length)



