T
tcomer
Hello. I'm working on a client/server application and I'm having some
weird issues with concatenating strings. The client program sends some
text:
Object objData = "IssuedCommand:SenderName";
byte[] byData =
System.Text.Encoding.ASCII.GetBytes(objData.ToString());
if (m_clientSocket != null)
{
m_clientSocket.Send(byData);
}
The server receives the data, decodes it and converts it into a string
value:
int iBytes = socketData.m_currentSocket.EndReceive(async);
char[] chars = new char[iBytes + 1];
System.Text.Decoder decode = System.Text.Encoding.ASCII.GetDecoder();
int charLen = decode.GetChars(socketData.dataBuffer, 0, iBytes, chars,
0);
decode.GetChars(socketData.dataBuffer, 0, iBytes, chars, 0);
string szCommand = new string(chars);
string[] receivedData = szCommand.Split(':');
Now at this point, receivedData[0] holds a value of "IssuedCommand" and
receivedData[1] is "SenderName". The problem is that if I try to use
either receivedData value in a string, it will print the correct
receivedData value but it will not display any text that is
concatenated. For example:
MessageBox.Show(receivedData[1].ToString() + " is now online.");
or
rtboxMessage.Text += receivedData[1] + " is now online.";
displays "SenderName" without the appended text " is now online." I
suspect this is a bug as there are no errors that are thrown. I have a
feeling that it may be caused by the Split statement, but I haven't
been able to solve the problem yet. Please let me know if I need to
provide more information.
weird issues with concatenating strings. The client program sends some
text:
Object objData = "IssuedCommand:SenderName";
byte[] byData =
System.Text.Encoding.ASCII.GetBytes(objData.ToString());
if (m_clientSocket != null)
{
m_clientSocket.Send(byData);
}
The server receives the data, decodes it and converts it into a string
value:
int iBytes = socketData.m_currentSocket.EndReceive(async);
char[] chars = new char[iBytes + 1];
System.Text.Decoder decode = System.Text.Encoding.ASCII.GetDecoder();
int charLen = decode.GetChars(socketData.dataBuffer, 0, iBytes, chars,
0);
decode.GetChars(socketData.dataBuffer, 0, iBytes, chars, 0);
string szCommand = new string(chars);
string[] receivedData = szCommand.Split(':');
Now at this point, receivedData[0] holds a value of "IssuedCommand" and
receivedData[1] is "SenderName". The problem is that if I try to use
either receivedData value in a string, it will print the correct
receivedData value but it will not display any text that is
concatenated. For example:
MessageBox.Show(receivedData[1].ToString() + " is now online.");
or
rtboxMessage.Text += receivedData[1] + " is now online.";
displays "SenderName" without the appended text " is now online." I
suspect this is a bug as there are no errors that are thrown. I have a
feeling that it may be caused by the Split statement, but I haven't
been able to solve the problem yet. Please let me know if I need to
provide more information.