problem with string function in vb.net

G

giannik

I am using this function :
Dim ArrColWidths() As String

ArrColWidths = Split(string.empty,";")

This always returns an array with 1 element .

Silly in my opinion.

Is there a way around this so that it returns an array with zero elements ?
 
C

Cor Ligthert [MVP]

giannik, what do you expect than,

What you write is (exactly) the same as

ArrColWidths = Split("",";")

I assume tht this is not your goal?

Cor
 
G

giannik

coming from vb 6 environment, the split function would return an empty
array.
Since I am passing an empty string (nothing ) I would expect also that
the array would contain nothing in it.
giannik

I wish to be able to parse a string with the split function
and then take some action according to if the array is empty or not.
Now if i choose ubound(ArrColWidths) I get back =1 when I would like to get
back zero or nothing.
giannik
 
L

Larry Lard

giannik said:
I am using this function :
Dim ArrColWidths() As String

ArrColWidths = Split(string.empty,";")

This always returns an array with 1 element .

Silly in my opinion.

But exactly as documented:
If Expression is a zero-length string (""), Split returns a
single-element array containing a zero-length string. If Delimiter is a
zero-length string, or if it does not appear anywhere in Expression,
Split returns a single-element array containing the entire Expression
string.
In fact the first case here is covered by the second case; it's just
listed explicitly for ... well, explicitness, I suppose.

Is there a way around this so that it returns an array with zero elements ?

Wrap it in your own function that does what you want.

What would you want Split("banana", ";") to return, incidentally ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top