[Gambas-user] Split: misleading Wiki

Fabien Bodard gambas.fr at ...626...
Tue May 23 08:38:22 CEST 2017


A=Split (replace ("gggg##yyy##1234","##",chr (27)),chr (27))

Or do not use double characters as separator .




Le 22 mai 2017 23:35, <d4t4full at ...626...> a écrit :

> Matti
>
> Your string has 3 substrings when split with SPLIT (STRING, "#"):
>
> Index 0: "Hello"
> Index 1: ""
> Index 2: "12345"
>
> It is documented that separators are single characters, not strings; you
> can specify a string because any of its individual characters may be used
> as separator.
>
> If you also specify IgnoreVoids as True, split should omit the null string
> and return only:
>
> Index 0: "Hello"
> Index 1: "12345"
>
> HTH,
> zxMarce.
>
> On May 22, 2017, 18:02, at 18:02, Matti <matti.eber at ...3240...> wrote:
> >Ok, thank you, Tobi.
> >I'll have to start thinking again (but not tonight anymore).
> >Matti
> >
> >Am 22.05.2017 um 22:17 schrieb Tobias Boege:
> >> On Mon, 22 May 2017, Matti wrote:
> >>> If I have a string sStr="hello##12345" and want to split it:
> >>>
> >>> Dim aSplit as String[]
> >>> aSplit = Split(sStr, "##")
> >>> Print aSplit[0], aSplit[1]
> >>>
> >>> Returns always only "hello". Maybe "12345" is excluded because being
> >an integer?
> >>>
> >> It is not an integer in this case. It's a string of characters and
> >Split()
> >> doesn't interpret it as an integer. Consequently it has nothing to do
> >with
> >> IgnoreVoid in my book.
> >>
> >> If anything is wrong, it is your use of the separator. According to
> >the
> >> documentation (and the implementation!), the Separator argument is a
> >*list*
> >> of separator characters, i.e. "##" will not split against the string
> >"##",
> >> but it will split against "#" or "#".
> >>
> >> To give a different example, if you had given the string
> >"abc#123,456" and
> >> separators "#," you would have gotten the array ["abc", "123",
> >"456"].
> >>
> >>> Now the Wiki says "StringArray = Split ( String [ , Separators ,
> >Escape , IgnoreVoid , KeepEscape ] )"
> >>> Where "IgnoreVoid" means "a boolean that tells Split() *not* to
> >return void elements."
> >>>
> >>> By trial and error I found out that "IgnoreVoid" has to be set to
> >'True' to return "12345". Exactly the opposite.
> >>>
> >>> The Wiki should be corrected here.
> >>>
> >> I don't know what's the problem with your installation but on mine I
> >get:
> >>
> >>    $ gbx3 -e 'Split("hello##12345", "##").Join("|")'
> >>    hello||12345
> >>
> >> i.e. it works. Notice the empty string between "hello" and "12345"
> >> in the context of what I explained about the separators above!
> >>
> >> Regards,
> >> Tobi
> >>
> >
> >-----------------------------------------------------------
> -------------------
> >Check out the vibrant tech community on one of the world's most
> >engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> >_______________________________________________
> >Gambas-user mailing list
> >Gambas-user at lists.sourceforge.net
> >https://lists.sourceforge.net/lists/listinfo/gambas-user
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list