Take off commas from a text reflecting a dynamic list

I have a text element that shows names from a list of contacts dynamically.

Is it possible to take off the commas separating each name?

The list operator that controls that is called “:join with”. The default join is ", " as you’ve discovered.

Whenever you render a list of texts, you can use :join with to control the separator between the list items.

This isn’t just a “cosmetic” feature. You can also use it to do things like turn a list of texts into a proper JSON argument array to feed to an external API or whatnot. It’s very handy! (Sort of a weird name, though, right?)

1 Like

if i want it to be separated by an “&”, but only between the last 2 items, is it possible?

Sure. One way to do that (I’m sure there are others) would be to get :count of the list first and subtract 1. Lets say your list has five names in it five-1 is 4. You’ll shove that into some custom state (or you might be able to do the math inline in your expression, hard to say) - let’s call it subcount. Display in your text element:

contacts:items until subcount:join with " " & contacts:last item

(Join the first 4 names with a space character. Then append an ampersand and display the last item.)

If you do this right, you’ll get (Edit: my example was faulty – I said there were 5 names, not 4 as in my original output example):

Tom Dick Harry Julian & Jane

(Edit: there - fixed it. Five names. Four separated by space, the last preceded by an ampersand.)

1 Like

but i never know a specific number of items that will be there, the amount always varies, so i cant hard code it

YOU’RE NOT HARD CODING IT. You get length from :count.

1 Like

tnx, will try it

This topic was automatically closed after 70 days. New replies are no longer allowed.