# Formula to Separate Concatenated Items?

OK, mighta gotten it:

``````IF( {Comma Count}>=5,
MID( {Style Name}&'\n',
FIND( '\n', {Style Name},
(LEN({Style Name 1})+2)+
(LEN({Style Name 2})+2)+
(LEN({Style Name 3})+2) )+1,
FIND( '\n', {Style Name}&'\n',
(LEN({Style Name 1})+2)+
(LEN({Style Name 2})+2)+
(LEN({Style Name 3})+2)+
(LEN({Style Name 4})+2) )
-FIND( '\n', {Style Name}&'\n',
(LEN({Style Name 1})+2)+
(LEN({Style Name 2})+2)+
(LEN({Style Name 3})+2) )-1 ) )``````

Yes, that works for the fifth field. Hereās the syntax for the sixth:

``````IF( {Comma Count}>=6,
MID( {Style Name}&'\n',
FIND( '\n', {Style Name},
(LEN({Style Name 1})+2)+
(LEN({Style Name 2})+2)+
(LEN({Style Name 3})+2)+
(LEN({Style Name 4})+2) )+1,
FIND( '\n', {Style Name}&'\n',
(LEN({Style Name 1})+2)+
(LEN({Style Name 2})+2)+
(LEN({Style Name 3})+2)+
(LEN({Style Name 4})+2)+
(LEN({Style Name 5})+2) )
-FIND( '\n', {Style Name}&'\n',
(LEN({Style Name 1})+2)+
(LEN({Style Name 2})+2)+
(LEN({Style Name 3})+2)+
(LEN({Style Name 4})+2) )-1 ) )``````

I wanted to apologize for not getting back to you; Iām guessing I experienced a browser crash part-way through my reply, since when I opened this thread, I was greeted by an edit window containing a partial response. (Anyone know if Discourse allows one to display any unfinished drafts on file?) I see you didnāt need me, thankfully.

I guess Iām one of those Santayana said were condemned to repeat the past, as I essentially recreated this post and base from scratch a couple of weeks ago. I havenāt tried a point-by-point comparison, but I have a feeling the newer version is a slightly more elegant solution (or, at least, explained more nicely).

Note in {URL4} example there is one closing ā)ā missing at the very bottom.

I posted an alternative solution in this topic.

I am also posting the formulas here in order to

• acknowledge that this topic was the inspiration for my solution
• highlight aspects of my refactoring that would have cluttered up the other topic
• make it easier to continue this conversation (where the formula writers are)

While this solution was inspired by W_Vann_Hallās post, the formulas are actually quite different.

• This solution does not need a field to count the number of items in the list, which reduces the complexity of the formulas. (The initial `IF` statement is not needed.)
• It uses a combination of `LEFT` and `RIGHT` functions, instead of the `MID` function. When building the functions, it was easier for me to mentally picture using the `RIGHT` function to identify everything remaining in the string, and then using the `LEFT` function to pick off the first item.
• It also reduces the overall amount and complexity of code by
• Using the `CONCATENATE` function instead of summing multiple `LEN` functions.
• Subtracting a single number that increases for each item, rather than repeatedly adding 2 for each previous item.

Here is a screen shot of the sample base.

Here is the formula for the field {Item1}.

``````IF( FIND(",", {List}),
LEFT({List},
FIND(",", {List})-1
),
{List}
)
``````

Here is the formula for the field {Item2}:

``````LEFT(
RIGHT({List},
LEN({List}) - LEN({Item1}) - 2
),
FIND( ",",
RIGHT({List},
LEN({List}) - LEN({Item1}) - 2
) & ","
)-1
)
``````

Here is the formula for the field {Item3}:

``````LEFT(
RIGHT({List},
LEN({List}) - LEN(CONCATENATE({Item1},{Item2})) -4
),
FIND( ",",
RIGHT({List},
LEN({List}) - LEN(CONCATENATE({Item1},{Item2})) -4
) & ","
)-1
)
``````

Here is the formula for the field {Item4}:

``````LEFT(
RIGHT({List},
LEN({List}) - LEN(CONCATENATE({Item1},{Item2},{Item3})) -6
),
FIND( ",",
RIGHT({List},
LEN({List}) - LEN(CONCATENATE({Item1},{Item2},{Item3})) -6
) & ","
)-1
)
``````

If you need more items, continue the pattern used for {Item3} and {Item4}:

• add the next item to both of the `CONCATENATE` functions
• subtract two more from the results of the `LEN` functions (e.g., for the 5th item, subtract 8; for the 6th item subtract 10, etc.) The number to subtract is determined by `(2 x the item number) - 2`. (Note you cannot put this in the actual formula because the item number is not a field.)
1 Like

Thank you, @kuovonne for your solution.
Do you think it may be extrapolated for undefined number of Items (max 10) and with the need to put each of them separately from the new line (after " \n ") in a long text field?

The formulas should work for far more than 10 items. Just keep following the pattern. I havenāt tried it for items with "\n ", but you could try it and let us know how it goes.

With the release of the new scripting block, I think that long workarounds like this will no longer be needed.