Change all strings

Hey community!

I have a table with multiple columns. I would like to change all “&” into “and” and all “,” into “;”.
So “Projects + Summary, comparison” will look like this “Projects and Summary; comparison”. Is there a faster way to do it than making this for all columns?
image

Greetings
Andrzej

Hi @jedrek,

You can use nested functions to do all manipulations in one node. To do it for several columns, you could use the Column Expressions node or manipulate columns in a loop starting with the Column List Loop Start node and ending with the Loop End (Column Append) node. For the second approach you have to create the expression as a flow variable and pass it to the String Manipulation node.

If you need more help, provide me with a sample data set and I will send you a workflow example.

:blush:

3 Likes

Dear @armingrudd

I cannot find this node (column expression) in my knime, I can see that I have to install an extension to do it. However I do not now which one is it. When I entered this link in browser, I couldn’t access it. In Knime, I couldn’t find this extencion.

Please, find attached file with dummy data. My original data looks almost this same.
example data.xlsx (9.4 KB)

You have to install “KNIME Expressions” extension.

I will get back to you with an example workflow.

:blush:

1 Like

Here is the workflow:

string_manipulation_loop.knwf (38.9 KB)

:blush:

3 Likes

Thank you a lot, you really helped me. Thank you :slight_smile:

2 Likes

Hey,

DO you know how I can handle it if I have some nulls in my dataset? I get this error when I try to run it
image

You need to add an if statement like this for all the expressions in the Column Expressions node:

if(!isMissing(column("Type")))regexReplace(regexReplace(column("Type"), "\\+", "and"), ",", ";")

By using the first approach with String Manipulation, you won’t need this.

:blush:

2 Likes

Fantastic! It is working, thank you :smiley:

2 Likes

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