Merging cells depending on consecutive values

Hi,

Screenshot 2025-02-27 184338

When a cell has backlash as a value I want to merge that cell with the succeeding two. So in the case of the screenshot example I attach, that would mean getting a cell with the values ‘\nT’ in it. It would probably require using a Substitute DAT but I am not sure what expression to use. Could someone suggest a solution?

Thanks!

Hi @Tasos_A,

there might be a different answer if you share the whole context of your question - as in: what is it you are trying to achieve in the end.

Just from what is here I assume you have a Table DAT with a single row, multiple columns of single characters and you want to merge cells if the \ character is present. Also, I assume there is no chance that a \ character is followed by another \ character in any of the 2 following cells.

As also the number of columns will change, the only thing I can think of is using a regular expression might be easiest.

For this first use a Convert DAT to convert the table to text followed by an Evaluate DAT where the Expression parameter should contain:

[''.join(filter(None, group)) for group in mod.re.findall(r'(\\..)|(.)', me.inputs[0].text)]

The pattern for .findall() is (\\..) meaning match any \ and the following 2 characters.

Lastly append a Convert DAT and convert back to a table with a space as the Split Cells at parameter.

cheers
Markus

Thank you for taking the time to reply Markus. You are right, I should have provided more context. What I was looking for is for a way to merge three cells together if the first contained a backlash and the second one a ‘n’. The overall motivation for that is that I wanted to apply per-letter formatting codes. I paste the fix here from the TD Facebook Help Group, courtesy of Jean-François Renaud, in case someone else encounters a similar issue:

By using the original table as input, we use a Script DAT to which we enter the code below: