microstudio icon indicating copy to clipboard operation
microstudio copied to clipboard

microScript : add `list.join( separator )`

Open SuperUserNameMan opened this issue 3 years ago • 2 comments

hello,

In microscript, we do have string.split( separator ).

Could we have list.join( separator ) too ?

SuperUserNameMan avatar Oct 28 '22 15:10 SuperUserNameMan

Hi,

You can achieve this in Microscript 2.0 using the prototypes feature:

List.join = function(separator) if this.length > 0 then local str = "" for i in this str = separator + str end return str.substring(1) else return "" end end

so:

a = ["a","b","c"]

print (a.join("-"))

it would output:

a-b-c

joseconsuegra avatar Dec 06 '22 13:12 joseconsuegra

That function actually exists, but I don't think it's documented (I don't know when it was added).

You can type this in the console to test if a function exists

> [].join

[native function]

That means the function exists, so you can try to figure out how to use it. Like this:

> [1,2,3].join(", ")  // notice I added a space too

"1, 2, 3"

Skaruts avatar Mar 24 '23 08:03 Skaruts