Home All Groups Group Topic Archive Search About

How to remove an empty array ?

Author
13 Jul 2006 6:56 PM
Rohan
how would i remove the empty array this is my function


Private Function FindMeter(ByVal txt As String) As MeterAccountName
        Dim TempTxt(3) As String
        TempTxt = Strings.Split(Trim(Right(txt, InStr(txt, ":") - 1)),
" ")

        FindMeter.Meter = TempTxt(1)
        FindMeter.xName = TempTxt(2)
        FindMeter.Account_No = TempTxt(3)

    End Function

Author
13 Jul 2006 7:54 PM
Branco Medeiros
Rohan wrote:
> how would i remove the empty array this is my function
>
>
> Private Function FindMeter(ByVal txt As String) As MeterAccountName
>         Dim TempTxt(3) As String
>         TempTxt = Strings.Split(Trim(Right(txt, InStr(txt, ":") - 1)),
> " ")
>
>         FindMeter.Meter = TempTxt(1)
>         FindMeter.xName = TempTxt(2)
>         FindMeter.Account_No = TempTxt(3)
>
>     End Function

The Split method of the String class allows for filtering out empty
entries, but only when passed an array of Char or String:

  Function FilteredSplit(Text As String, Sep As Char) As String()

    Return Text.Split(New Char() {Sep}, _
    StringSplitOptions.RemoveEmptyEntries)

  End Function

> Private Function FindMeter(ByVal txt As String) As MeterAccountName
>         Dim TempTxt(3) As String

    'Hmmm, wouldn't it be InStrRev(Text, ":") + 1 ?
    TempTxt = FilteredSplit(Right(Text, InStr(Text, ":") - 1), " "c)
>
>         FindMeter.Meter = TempTxt(1)
>         FindMeter.xName = TempTxt(2)
>         FindMeter.Account_No = TempTxt(3)
>
>     End Function

HTH.

Regards,

Branco.
Author
13 Jul 2006 7:58 PM
Mattias Sjögren
>how would i remove the empty array this is my function

What do you mean by removing the array? Keep in mind that .NET is a
garbage collected environment. You don't explicitly delete objects,
the garbage collector does that for you eventually.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.