| csrocker101 |
Apr 2nd, 2007 2:22 PM |
Help with breaking apart a string
FIrst off I want to thank everyone for being extremely helpful as I try to complete a pretty big computer science project. I have got a server application and a client application and a database application.The database application is connected with the server application which logs and updates the information sent to it via the client . Its rather simple to update the database via the client you send the server a carriage and line return. Basically updating the database consists of sending a username string and a location string to the streamwriter such as "322095 In the labs" to the server. Putting a space in between two strings tells the server to update. If you do not wish to update the database only one string is passed with no space. So for instance if you do not wish to update the database a string passed to the stream writer looks like this "322095" which will then tell you were the student is. The problem I am having is in my server. 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();
Basically the string clientInfo is the information the client sends to the server via the streamwriter. My problem is that the string will just appear as "322095 In the labs" but I want to check this invididual string to see if there is a space in between it. So for instance:
:
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();
if(clientInfo == IF THERE IS A SPACE BETWEEN THE VARIABLES)
{
//updateDatabase Commands
}
else
{
//dont update database
}
Obviously this is pseduocode but I want to know if I can check if there is a space in between the read in string. Is there a way I can do this?? I think the main problem is that the two strings are combined into one when i send it via the streamwriter, but i want to know if theres some way I can check if there is a space in just one string. I would appreciate some help. Thanks
|