How to split a string into rows of each character without Java Snippet

I am currently solving Advent of Code 2020 for learning KNIME.
On day 6, I want to split a string into rows of each character and have found a way to do this using Java Snippet. Is there any other way to do this?
Also, any other workflows for AoC 2020?

My workflow is on KNIME Community Hub.

Hi,
I think you are looking for the “String Splitter (Regex)” node. Just activate the “option” set or row.
Unluckely I’m not an expert in regex so I cannot help regarding the needed expression

2 Likes

Thanks for your reply, I guess regex could do it. So far it hasn’t worked, but I have high hopes for string splitter.

Anyway, follwing pattern did not work.

pattern (.) oprtion rows/list
pattern (.)+ oprtion rows/list

1 Like

Hi @Motoi_Tokimatsu ,

I went in search of the original Advent of Code question that was posed, and found it here. This will hopefully be useful to anybody wishing to understand what the challenge is.

It is an interesting question, and in the past I have used java snippet to break cells down into individual characters, which is one of the issues you face. I even wrote a component that did just that when I first started with KNIME

However, your question is how to achieve it without java snippet, so that rules out my component :wink:

Take a look at this… hopefully the annotations explain sufficiently…

Workflow attached here for download
AoC2020Day6-takbb.knwf (1.3 MB)

3 Likes

I thought I’d add something about the use of regex here. I used regex, but not in String Splitter (Regex). Instead I used it in the String Replacer node, to prepare the data so that it could be split using Cell Splitter.

The pattern to search for is
(.{1})

and what this does is “captures” every individual character

This is replaced by
$1¬
which means take the captured character ($1 refers to “capture group number 1”) and writes it back followed by the ¬ character which I am using as a delimiter.

This delimiter is then used by the Cell Splitter to split out every character into a Set.

The String Manipulation was added in between the two because I discovered your data sometimes had spaces, which I wanted to filter out so they wouldn’t get counted. I could have alternatively filtered spaces near the very end of the flow (after the Ungroup) using Row Filter.

1 Like

I really learned a lot by showing the workflow with detailed comments. And KNIME makes it easy to add new nodes. Thank you very much.

1 Like

That’s good to hear @Motoi_Tokimatsu , and welcome to the KNIME community.

1 Like

Thanks. I checked it :smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.