.net - String not printing as expected -


Can you please explain why the output window does not print the "xxxxx" part of the string? It seems that I do not have some basic understanding about some things ...?

I am sending string messages to TcpClient, and when creating strings, does not add a special character on the sender side, and neither is the part of this problem towards the receiver?

Enter image details here


Edit:

I am making my string like this on the sender side:

  Private Sub SendData (ByVal stringArray As string ()) SendData (GetMessageString (stringArray)) End Sub Public Function GetMessageString (ByVal array string) as string string str str = "as for" as I = 0 array.Length To - 1 Str = str & amp; Array (i) if i & lt; Array.Length - 1 then str = str & amp; "|" Finish the next return str termination function   

and towards receiving, the variable has been created:

  client.GetStream.BeginRead (readBodyBuffer, 0, MESSAGE_BODY_LENGTH, New AsyncCallback (AddressOf ReadBody), nothing) ... Private Sub ReadBody (ByVal aread as IAsyncResult) BytesRead = client.GetStream.EndRead (aread) ... 'Read (Add) buffer messagePart = Encoding (ReadBodyBuffer) in .ASCII.GetString MessagePart = messagePart & amp; "Xxxxx"   

edit 3

ReDim was misused my usual mistake byte array: (parameter 10 11 elements)

incorrect:

  ReDim readBodyBuffer (MESSAGE_BODY_LENGTH)   

Correct:

 < Code> itemprop = "text"> 

I believe it is someone It is also related to the print that can not be printed. For example, this C # code:

  string message = "Hello \ 0 hello 2"; Debug.Print (message);   

Here I have a string with an empty character at the end. In Debug Visualizer it appears as if I made this string - "Hello \ 0 Hello2" . But it does not display \ 0 in the output window and even leaves Hello 2 . So I think this is related to your problem, although I could not reproduce it completely. Check your messagePart.Length .

Update: Okay, after going through all these comments here and in another answer I think the reason for the problem is readBodyBuffer , how it allocates this buffer, but I hope you are creating a new byte array with fixed (11) length, then you actually get the number of bytes received Ignoring (10) and ASCII encoding Obtained using are converted string from the array. The fact is that less than the byte read allocated buffer size is the fact that the last byte in the array is zero. You should use the encoding. ASCII.GetString method that accepts the length argument, so that you do not get the \ 0 result in the string:

  messagePart = encoding. ASCII.GetString (readBodyBuffer, 0, ReadBytes)    

Comments