![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Dec 2006
Posts: 49
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
Use the IndexOf() function...
int pos = clientInfo.IndexOf(" ");
if (pos > 0)
Console.WriteLine("Space in the string.");
else
Console.WriteLine("NO space in the string.");
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Makes me wonder how I used to tolerate doing string manipulation in C.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
Hah, That was quite a pain... In C, I would just loop through each element and compare it to " " and if it was equal would return true.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Dec 2006
Posts: 49
Rep Power: 0
![]() |
Thanks so much Infinite Recursion Helped alot!
![]() |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
np man, glad to help.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Function Parameters | grimpirate | PHP | 10 | Mar 14th, 2007 6:55 PM |
| C# corruption!!! | Kilo | C++ | 32 | May 21st, 2006 8:44 PM |
| Array issues :( | Alo Tsum | Java | 10 | Nov 26th, 2005 5:45 PM |
| A standards question, optional inputs into Methods | Arla | C# | 4 | Apr 27th, 2005 10:38 PM |
| replace space with ' * ' | TecBrain | C++ | 15 | Apr 13th, 2005 12:32 PM |