Home All Groups Group Topic Archive Search About

problem with string function in vb.net

Author
2 Jul 2006 8:46 AM
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 ?

Author
2 Jul 2006 10:09 AM
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

Show quoteHide quote
"giannik" <gian***@freemail.gr> schreef in bericht
news:u8qjUQbnGHA.5096@TK2MSFTNGP03.phx.gbl...
>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
> ?
>
>
>
>
>
>
Author
2 Jul 2006 2:47 PM
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


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%235Bqi9bnGHA.1652@TK2MSFTNGP02.phx.gbl...
> 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
>
> "giannik" <gian***@freemail.gr> schreef in bericht
> news:u8qjUQbnGHA.5096@TK2MSFTNGP03.phx.gbl...
>>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
>> ?
>>
>>
>>
>>
>>
>>
>
>
Author
3 Jul 2006 10:47 AM
Larry Lard
giannik wrote:
> 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 ?

--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using