May 24, 2019, 11:19:19 PM

Author Topic: String.Join doesn't work  (Read 93 times)

Offline imaginaryhuman

  • Jr. Member
  • **
  • Posts: 10
String.Join doesn't work
« on: April 27, 2019, 06:29:25 PM »
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.

Offline Henri

  • Full Member
  • ***
  • Posts: 198
Re: String.Join doesn't work
« Reply #1 on: April 27, 2019, 06:46:45 PM »
Hi,

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

Code: BlitzMax
  1. Local a:String="hello,hi,howdy"
  2. Local b:String[]=a.split(",")
  3. Local delimiter:String = "!"
  4. Local c:String= delimiter.join(b)

or..

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

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

Offline imaginaryhuman

  • Jr. Member
  • **
  • Posts: 10
Re: String.Join doesn't work
« Reply #2 on: April 27, 2019, 06:56:23 PM »
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).

Offline Henri

  • Full Member
  • ***
  • Posts: 198
Re: String.Join doesn't work
« Reply #3 on: April 27, 2019, 08:16:43 PM »
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

Offline imaginaryhuman

  • Jr. Member
  • **
  • Posts: 10
Re: String.Join doesn't work
« Reply #4 on: April 27, 2019, 08:38:50 PM »
Yeah. "Split" is there... so should make sense to have a join.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2087
Re: String.Join doesn't work
« Reply #5 on: April 27, 2019, 08:50:18 PM »
Strings have split() and so have join()

Arrays neither have split() nor join().


Bye
Ron