[Gambas-user] Remove Null or Empty items in arrays.

Bruce Steers bsteers4 at gmail.com
Wed Jun 21 19:47:57 CEST 2023


On Wed, 21 Jun 2023, 17:37 Martín, <mbelmonte at belmotek.net> wrote:

> El 21/6/23 a las 13:08, Bruce Steers escribió:
> > Public Sub ArrayClean(MyArray As Variant) As Variant
> >
> >   Dim hArray As Variant = MyArray.Copy()
> >   For c As Integer = hArray.Max DownTo 0
> >     If Not hArray[c] Then hArray.Remove(c)
> >   Next
> >
> >   Return hArray
> >
> > End
>
> I like this code you propose, thank you.
> But I was wondering, since there is .Shuffle or .Sort, maybe it would be
> a good idea to have .RemoveEmpty.
>

For a string array it's even easier, you can simply use Array.Join() and
Split()

MyArray = Split(MyArray.Join("|"), "|", Null, True)

BruceS

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230621/b105e488/attachment-0001.htm>


More information about the User mailing list