VB Split versus .NET split functions returning diff results?

J. Scott Elblein

Well-known member
Joined
Dec 14, 2006
Messages
166
Location
Chicago
Programming Experience
10+
On the same source text that i am parsing, using:

VB.NET:
Dim strCountUnread() = wbr.DocumentText.Split(">Unread<")

Returns a different, seemingly random sized array each time its run, and can be in the thousands, and it's not actually splitting at that string, while:

VB.NET:
Dim strCountUnread() = Microsoft.VisualBasic.Split(wbr.DocumentText, ">Unread<")

Is returning the true number of Unread's, (which is 10) reliably.

I know I could just use the working one, but I'd like to understand why the .NET version is not working?

Thanks
 
String.Split doesn't have any overload that takes only a single parameter of type String. It does have one that take a ParamArray of char. Apparently that is what it is considered by this function, and strangely only a single char. The equivalent String.Split function to use is one of those that takes String arrays as parameter, for exampel
txt.Split(New String() {"Unread"}, StringSplitOptions.None)
It might be easier for you to see this when you look at the documentation overview of String.Split where all overloads are presented. Also intellisense will give you all this information when you are writing the code, for instance type "wbr.split(" and browse the intellisense dialog for all 6 overloads of the Split method.
 
If you had turned Option Strict On the compiler would have informed you that you were doing something that could potentially cause an issue. I suggest you turn it On immediately for the current project and all future projects.
 
Back
Top