Count the commas of several

Good afternoon, please I would like you to help me, I cannot count the commas of several columns

String Manipulation node assumes just one line of code. To use many columns at once, install and use Column Expression node.

3 Likes

Hi @jimena_pedraza and welcome to the Knime Community.

This can be achieved with the String Manipulation (Multi Column) that you are using, however, you are not exactly using it correctly.

There is a reason why this “$$CURRENTCOLUMN$$” appears in the Expression. I’ll explain a bit.

For this example, I’ll use this sample data:
image

In the String Manipulation (Multi Column), you first choose what are the columns that you want the operations to be done on (in this case I only want the 3 address columns):

Now, by default, this is how the Expression window looks like:

This “$$CURRENTCOLUMN$$” represents each of the columns that were selected, in my case, they will be the 3 address columns. The idea behind this node is to apply the same operations (in this case it will be count()) on multiple columns, and each of these columns is represented by “$$CURRENTCOLUMN$$”, and it appears in the Expression to help you so that you do not need to remember how to write it.

So, the way you are using the node kind of defeats the purpose of the node as you are manipulating columns from the Column List.

In the end, the only thing you need to do is this:

I used the count() + 1 since it looks like what you want to do from your screenshot.

I appended the results as new columns, and set the suffix to _count, which gives this results:

Here’s the workflow:
count of commas per certain columns.knwf (7.1 KB)

Note: This can also be done via the Column Expression as @izaychik63 pointed out, and also by other methods. But since I saw that you were attempting to use the String Manipulation (Multi Column), which is actually a very straight forward method, I just wanted to show you how to properly use the node.

5 Likes

It’s easier to use Java Snippet.

String[] myArray = myString.split(",");
int count = myArray.length;

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