[Gambas-user] How to extend the String[] class ??
T Lee Davidson
t.lee.davidson at gmail.com
Thu Nov 23 17:54:49 CET 2023
On 11/23/23 08:02, Benoît Minisini wrote:
> You can't create a class in the IDE with the "[]" characters in the name, so you can't extend the "String[]" class.
>
> "[]" in a class name is a bit special. "String[]" is a normal class, but, for example, "Collection[]" or "String[][]" is an
> array of a normal class. It's a normal class, except that it is automatically created at runtime the first time you use it.
>
> So allowing "[]" in a class name may lead to some problems at the moment. I must think about that.
>
> But you can use normal class name for inheriting "String[]", it should work.
>
> Regards,
>
> --
> Benoît Minisini.
So then, something like this:
[StringArray.class]
' Gambas class file
Export
Inherits String[]
Public Sub Squash() As String[]
Return Split(Super.Join(","), ",", Null, True) ' I like that code, Guianluigi; very slick.
End
[/StringArray.class]
[Main.module]
' Gambas module file
Public Sub Main()
Dim myStringArray As StringArray
myStringArray = ["risotto", "", "Pascualina", "focaccia"]
myStringArray = myStringArray.Squash()
For Each s As String In myStringArray
Print s
Next
End
[/Main.module]
--
Lee
More information about the User
mailing list