Strange! Split() function is not working as expected.

July 10, 2006

I work on VS .NET 2003 and mostly on VB. Recently when I was doing a new module in my project wherein I had to do a HTTP request to a servlet hosted by Tomcat server and get the response string. I get the response string as a huge bulk of strings seperated by NewLine character. I had to loop through the strings and get the valid string. So the simple thing I could think of is doing a Split(“\n”) on the response string so as to get the array of lines. I did the same and was surprised to find that the Split() was not working as expected. It just gave me a single line in the array where as the response bulk contained almost 120 strings seperated with newline.

I had to do a small change in the code, instead of doing a Split() I created a StringReader object from the bulk response. And then I just looped using the StringReader.ReadLine() which worked fine as expected.

Thinking, is there a bug in Split() or something else. If anyone has same troubles or any suggestion, just post a comment.



One Response to “Strange! Split() function is not working as expected.”

  1. passing through Says:

    now you did make sure that \n is the delimiter, right. what if it is just \r. or what if it is \f. stringReader.readLine() has the built-in capability to detect that. split() does not. you have to build it in yourself.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: