"join list using separator" block

out2lunch

  • Posts: 118
To complement "split text using separator".  This would return a string.

Code: [Select]
join [list] using separator [separator]

public function ListJoin(__list:Array<Dynamic>, __separator:String):String
{
    return __list.join(__separator);
}
Clacky Train has been released worldwide on the App Store!
Voodoo Zombie's 1.4.1 update has more bosses and magic items on the App Store!
Here's the Launch Trailer on YouTube.

Hectate

  • *
  • Posts: 4645
I'm not sure I understand, why would you need a separator to join a string? If you use the "text + text" block (or the code involved) it will append the second to the end of the first - isn't that sufficient?
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

out2lunch

  • Posts: 118
It's sufficient if you're only joining two elements. That's not what this is for, it's for large amounts of elements in a list.  The text + text code would get unwieldy.

var string = text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text + "," + text;
Clacky Train has been released worldwide on the App Store!
Voodoo Zombie's 1.4.1 update has more bosses and magic items on the App Store!
Here's the Launch Trailer on YouTube.

rob1221

  • *
  • Posts: 9474
Just loop through the list and set a text attribute to itself + separator + the current list item.

out2lunch

  • Posts: 118
I wasn't asking for a workaround, I already have the join code in my project.  I was suggesting something that programmers would appreciate and understand - a nice one liner that does everything for you instead of the mess you have to make to work around it.

Since Stencyl already has split, I thought it's counterpart might be appreciated.

« Last Edit: December 12, 2013, 04:41:10 pm by out2lunch »
Clacky Train has been released worldwide on the App Store!
Voodoo Zombie's 1.4.1 update has more bosses and magic items on the App Store!
Here's the Launch Trailer on YouTube.

Hectate

  • *
  • Posts: 4645
I see what you mean, yes. Nesting the text+text block can get annoying when combining several elements (not that I do it frequently, so perhaps that's why I didn't see the use case right away).

:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Jon

  • *
  • Posts: 17533
Though not the most common operation, it's a good one to add in for the future.