Alrite guys this is my last post and I will stop polluting this C# forum with stupid questions. Basically my client sends a string to server and if there is a space in the string you update the database. What I am trying to do is using the .IndexOf() function and I am assigning everything before the space to string called username and the characters after the space to a string called location. the username variable works just fine. But my location string is not working and throws an exception everytime. Here is my Code:
public void doRequest()
{
//streamReader reads incoming connection from client
StreamWriter sw = new StreamWriter(socketStream);
StreamReader sr = new StreamReader(socketStream);
//writes in coming data
//Assigns data from the streamreader to a string
string clientInfo = sr.ReadLine();
int pos = clientInfo.IndexOf(" ");
//assigns string info from stream reader to a char
char[] newInfo = new char[clientInfo.Length];
//for loop converts each string character to a char character
for (int i = 0; i < clientInfo.Length; i++)
{
newInfo[i] = Convert.ToChar(clientInfo[i]);
}
//uses the string constructor to assign everything after .IndexOf(" ")
//and to the end of the array to location
string location = new string(newInfo, pos + 1, clientInfo.Length);
//assigns everything from the start of the array to the .IndexOf(" ")
//to username
string username = new string(newInfo, 0, pos);
Where I have string location it throws an exception EVERYTIME which says "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: startIndex"}" The string username assigns nad works just fine. Any suggestions??! and I'd once again like to thank everyone for their help.