Hi guys,
Maybe this is a stupid question but I cannot find a solution. If I have a single cell with a multi-row string, how can I split it in different rows?
Thanks in advance
Gio
Hi,
you can use a Cell Splitter node with the delimiter \n
for that. Make sure to check: Use \ as escape character and tick Output As List.
Then connect an Ungroup node to split the collection column into individual rows.
Example workflow:
– Philipp
Hi,
I’ll take a quick stab at it. Here’s one way:
First count the number of lines in the cell. You can do this with the String Manipulation node and the expression count($multiLineText$, "\n") + 1
.
Next use the One Row To Many node to create a separate row for each line of text (use value from previous step to specify number of rows to create).
Next use Math Formula to number each line (make col name = “line num index”).
Finally use Column Expressions and the expression split(column("multiLineText"), "\n")[column("line num index")]
this expression creates an array of lines by splitting the multiline text using the delimiter “\n” (line end character).
First Table:
![image](https://forum-cdn.knime.com/uploads/default/original/2X/a/a2915edc04b064ab8217b8930336ba11cac6422a.png)
Last table:
![image](https://forum-cdn.knime.com/uploads/default/original/2X/8/875d6ce4057465725676a531383b7f8e1d3a3b04.png)
See attached workflow. You’ll probably need to tweak it to meet your needs and make it more robust. To make it work for a whole table enclose it in a loop (e.g. Chunk Loop Start using n=1, and Loop End nodes). Hope this helps. -Don
split lines within cell.knwf (13.2 KB)
Great. Thank you both!
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.