如何從此代碼中獲取字符串而不是char數組?VB.NET TCP服務器套接字編程 - 從字節接收字符串
客戶端代碼:
stm = tcpClient.GetStream()
Dim ascenc As New ASCIIEncoding
Dim byteData() As Byte = ascenc.GetBytes(strMessage(counter))
Thread.Sleep(2000)
Console.WriteLine("Transmitted ")
stm.Write(byteData, 0, byteData.Length())
Server代碼:
Dim size As Integer = TcpSocket.Receive(bitData)
Dim chars(size) As Char
For i As Integer = 0 To size
chars(i) = Convert.ToChar(bitData(i)) // i want to get the string directly, how ?
Next
Dim newString As New String(chars)
Console.WriteLine(newString)
strMessage(counter) = newString
[嘗試](https://msdn.microsoft.com/en-us/library/ms172827.aspx)[使用Google](https://www.dotnetperls.com/convert-string-byte- array-vbnet)[at](http://stackoverflow.com/questions/1003275/how-to-convert-byte-to-string)[all?](http://www.convertdatatypes.com/Convert-Byte -Array-to-String-in-VB.net.html) –