[Gambas-user] Split: misleading Wiki
Tobias Boege
taboege at ...626...
Mon May 22 22:17:54 CEST 2017
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
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list