![]() |
Throwing an exception when using string constructor
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()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. |
Can you give us the stack trace? And what are the values of the variable at the line that is throwing the exception? Are the strings being properly encoded and decoded when going across the socket?
I suspect that a little use of debugging utilities or logging what is happening will help you find your problem. |
The stream is coming in just fine and my char array has exactly the information I want. IT works just fine when you use
string location = new string(newInfo, 0, clientInfo.Length); But if you put anything other than 0 as the index, it throws an exception! stilll don't know why! |
I found the problem. For some reason it was adding an additional index with the IndexOf(" ") function so to solve it. I just did:
string location = new string(newInfo, 0, clientInfo.Length - pos); and it works just fine now. odd! but if it works it works :D |
| All times are GMT -5. The time now is 2:19 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC