Split with empty fields

I’m trying to use split to separate tab-delimited text into a String array.
I’m getting weird crashes, and I am wondering whether it is due to Split.
Code looks like

Dim fields(-1) As String

fields = textLine.Split(Chr(9))

I then go on to call functions that are meant to have String arguments, and use Val() to turn some fields into Integer and Single

First question, which is not answered in the documentation, is what happens if the original string has two tabs in a row. Does that result in a Nil, empty String, or what? I am about to figure that out, but nevertheless, I thought perhaps someone knew about problems with Split, or perhaps using Val with an empty string, or some other bug that might cause the crashes.

TIA

Split literally just splits at your separator and stores the text between the separators in an array element. If there is nothing between them, you will get an empty string.

dim s as string = chr( 9 ) + chr( 9 )
dim arr() as string = s.Split( chr( 9 ) )
// arr.Ubound = 2
// arr( 0 ) = ""
// arr( 1 ) = ""
// arr( 2 ) = ""

OK that sounds sensible. I’m guessing then that Split is not where my problem is. Thanks so much

With the old framework, it’s impossible to get the string functions (Left, Right, Mid, Split) to crash unless you do something like feed them a Variant that can’t be converted to a string. You can do non-sensical stuff like s.Left( -5) or s.Mid( -5, -3 ) and get strange results, but no crash.

Yes as it should be. Principle of least surprise.

This isn’t the case in the new framework. The equivalent calls will raise exceptions if the parameters don’t make sense. For example:

dim t as Text = "a"
t = t.Left( 3 ) // OutOfBoundsException!