[Gambas-user] Opposite of Split
Laurent Carlier
lordheavy at ...512...
Thu Jun 16 17:20:18 CEST 2005
Le Jeudi 16 Juin 2005 16:29, Eilert a écrit :
> Hi,
>
> is there an opposite of the Split function? Something like "join" or so
> that can put together the contents of an array into a string, separated
> by any separator?
>
> Rolf
Here it's better :) :
PUBLIC SUB Main()
DIM myarray AS NEW Variant[]
myarray.Push(12)
myarray.Push("a string")
myarray.Push(Now)
PRINT join(myarray, ",")
END
PUBLIC FUNCTION join(tArray AS Variant[], OPTIONAL separator AS String = " ")
AS String
DIM myvar AS Variant
DIM mystr AS String
FOR EACH myvar IN tArray
mystr = mystr & CStr(myvar) & separator
NEXT
RETURN Left$(mystr, -1)
END
=> 12,a string,06/16/2005 17:18:14
--
Laurent Carlier
jabber : LordHeavy at ...943...
More information about the User
mailing list