Hello!
I'm trying to read data from a stream and append them into string builder and then take the read data to a string. Here is the code I'm using to do that.
It seems like there is a problem with the code, because I don't get the whole data assigned to the message variable in the end of the while loop. I started debugging the code and checked the values it gets for strTemp. Though in every loop strTemp gets different string values, in the what end I get for the message is the value which was assigned to strTemp at the first loop. It seemed like, the problem was with appending of the string with string builder. I trined string.concat and message+=strTemp but non of them helped. Anyone know the reason? Please help. Thanks!
I'm trying to read data from a stream and append them into string builder and then take the read data to a string. Here is the code I'm using to do that.
Dim intNumOfBytesToRead As Integer = Val(getMessageSize(msgNumber)) 'getting the size of the message Dim dataIn(intNumOfBytesToRead) As Byte Dim intNumOfBytesRead As Integer = 0 Dim strTemp As String = Nothing Dim builder As StringBuilder builder = New StringBuilder("") While (intNumOfBytesToRead > 0) n = strm.Read(dataIn, 0, dataIn.Length) If n = 0 Then Exit While End If intNumOfBytesRead += n intNumOfBytesToRead -= n strTemp = Encoding.ASCII.GetString(dataIn) builder.Append(strTemp) message=builder.ToString End While Form1.rrtxtOutput.Text = message
It seems like there is a problem with the code, because I don't get the whole data assigned to the message variable in the end of the while loop. I started debugging the code and checked the values it gets for strTemp. Though in every loop strTemp gets different string values, in the what end I get for the message is the value which was assigned to strTemp at the first loop. It seemed like, the problem was with appending of the string with string builder. I trined string.concat and message+=strTemp but non of them helped. Anyone know the reason? Please help. Thanks!