Log In  

Cart #knutil_join-1 | 2022-09-10 | Code ▽ | Embed ▽ | No License

Feature Overview

JOIN() Join strings with a delimiter.

  • Joins the argument strings with the specified delimiter.
  • This function consumes 25 Token.

?join(' ',unpack({'test','[join]','is','ok!\n\n'}))



This function is included in the KNUTIL library.

release note


  • variable argument support by tuple


  • first release
P#59961 2022-09-10 15:45 ( Edited 2022-09-10 16:08)


very nice!

here's a 4-token save: (25->21)

function join(d,s,...)
  return ... and s..d..join(d,...) or s or ''
P#123135 2022-12-27 18:46

Yes! That's a great option!

The difference between those two codes is not only the difference in tokens.
If the argument is nil, it will either "stop with an error" or "skip the join process".

You can choose the one that is appropriate for your project.

Thanks. @pancelor

P#123597 2023-01-03 13:22

I don't understand, can you give an example that behaves differently under the two implementations? this prints true 3 times

function join1(d,s,...)
  return not s and '' or not ... and s or s..d..join(d,...)

function join2(d,s,...)
  return ... and s..d..join(d,...) or s or ''

?join1(" ")==join2(" ")
?join1(" ","hi")==join2(" ","hi")
P#123615 2023-01-03 18:56


The difference is whether to output an error when nil is specified for the s argument.

JOIN1: Type that ignores errors

JOIN2: The type that outputs errors

In case you are wondering, I have join() mixed up in the join1() and join2() code you wrote...

P#123630 2023-01-04 02:16

ahh that makes sense, thanks. (oh! yep I typoed my join1 and join2 definitions, whoops)

P#124139 2023-01-12 13:32

[Please log in to post a comment]