[Gambas-user] Opposite of Split

Eilert eilert-sprachen at ...221...
Thu Jun 16 17:09:44 CEST 2005


Laurent Carlier schrieb:
> 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
>>
> 
> 
> Something like that ? :
> 
> PUBLIC SUB Main()
> 
>   DIM myarray AS NEW Variant[]
>   DIM myvar AS Variant
>   DIM mystr AS String
> 
>   myarray.Push(12)
>   myarray.Push("a string")
>   myarray.Push(Now)
> 
>   FOR EACH myvar IN myarray
>     mystr = mystr & CStr(myvar) & " "
>   NEXT
> 
>   PRINT mystr
> 
> END
> 

Hi Laurent,

yes, this is it:

   FOR EACH myvar IN myarray
     mystr = mystr & CStr(myvar) & " "
   NEXT

I forgot the FOR EACH thing does exist. That makes it somewhat easier. 
What I really meant was

mystr = Join(myarray, " ")

But then, the CStr() would be missing, mystr and myarray would have to 
be of the same type (String) or the conversion would have to be implicit.

Rolf






More information about the User mailing list