String.Join doesn't work

Started by imaginaryhuman, April 27, 2019, 18:29:25

Previous topic - Next topic

imaginaryhuman

Local a:String="hello,hi,howdy"
Local b:String[]=a.split(",")
Local c:String=b.join("!")

Error message is: "compile error - identifier join not found"

Tried it a bunch of different ways. Joining a string array back together does not compile.

Henri

Hi,

array doesn't have join-method, you have to use string.

Code (blitzmax) Select

Local a:String="hello,hi,howdy"
Local b:String[]=a.split(",")
Local delimiter:String = "!"
Local c:String= delimiter.join(b)


or..

Code (blitzmax) Select

Local a:String="hello,hi,howdy"
Local b:String[]=a.split(",")
Local c:String= "!".join(b)


-Henri
- Got 01100011 problems, but the bit ain't 00000001

imaginaryhuman

I see. the thing to join with has to come first and then the things being joined are in the brackets.

kinda weird, better syntax would be like javascript, string[].join(delimiter).

Henri

I guess someone forgot to put join() into arrays ?

There is already Sort() and Dimensions() , so implementing Join() wouldn't be that of a stretch.

-Henri

- Got 01100011 problems, but the bit ain't 00000001

imaginaryhuman

Yeah. "Split" is there... so should make sense to have a join.

Derron

Strings have split() and so have join()

Arrays neither have split() nor join().


Bye
Ron

Midimaster

Correct use of Join()

Because this thread forgot to demonstrate the correct use of Join() at the end, I now write some lines about it:

Join() is very usefull to receive a STRING with a given length of the same ASCII characters

This will print 30 times the "!" sign
Local A:String = "!".Join(New String[30])
Print A



Or you put it into a function:
Print StringChain("*",50)

Function StringChain:String(Char:String, Length:Int)
    Local size$[Length]
    Return Char.Join(size)
End Function
This will print 50 times the "*" sign


And it is also perfect to trim the length of strings:

For Local i:Int=1 To 10
Local value:Int = 2^Rand(0,30)
Local t:String  = String(value)
t = SPACE(12-t.length) + t
Print  "|" +  t + " |"
Next

Function SPACE:String(Length:Int)
Local size$[Length]
Return " ".Join(size)
End Function 
this prints something like:
|  268435455 |
|    1048576 |
|          4 |
|      32767 |
|     131071 |
|    2097152 |
|      16383 |
|          4 |
|          4 |
|    2097152 |
...crossing the alps with my bike at the moment