Combine expressions

Hi All,

I am facing difficulties to combine the replace expressions in String Manipulation node.

The expressions are below:
replace($$CURRENTCOLUMN$$, “PRE1-ENG”, “P1HD”)
replace($$CURRENTCOLUMN$$, “PRE1-FULLDAY-ENG”, “P1FD”)
replace($$CURRENTCOLUMN$$, “PRE2-ENG”, “P2HD”)
replace($$CURRENTCOLUMN$$, “PRE2-FULLDAY-ENG”, “P2FD”)
replace($$CURRENTCOLUMN$$, “PRE3-ENG”, “P3HD”)
replace($$CURRENTCOLUMN$$, “PRE3-FULLDAY-ENG”, “P3FD”)
replace($$CURRENTCOLUMN$$, “PRE3-FULLDAY-MAN”, “P3FD”)
replace($$CURRENTCOLUMN$$, “REALTOTS Full Day”, “TotFD”)
replace($$CURRENTCOLUMN$$, “NURSERY-FULLDAY-ENG”, “P1FD”)
replace($$CURRENTCOLUMN$$, “NURSERY-HALFDAY-ENG”, “P1HD”)
replace($$CURRENTCOLUMN$$, “PRE-JUNIOR-FULLDAY-ENG”, “P3FD”)
replace($$CURRENTCOLUMN$$, “PRE-JUNIOR-HALFDAY-ENG”, “P3HD”)
replace($$CURRENTCOLUMN$$, “PRE-NURSERY PLUS-HALFDAY”, “PNHD”)
replace($$CURRENTCOLUMN$$, “RECEPTION-FULLDAY-ENG”, “P2FD”)
replace($$CURRENTCOLUMN$$, “RECEPTION-HALFDAY-ENG”, “P2HD”)
replace($$CURRENTCOLUMN$$, “PRE-JUNIOR-FULLDAY-MAN”, “P3FD”)
replace($$CURRENTCOLUMN$$, “PRE-JUNIOR-HALFDAY-MAN”, “P3HD”)
replace($$CURRENTCOLUMN$$, “REALTOTS Half Day”, “TotHD”)
replace($$CURRENTCOLUMN$$, “RECEPTION-FULLDAY-MAN”, “P2FD”)
replace($$CURRENTCOLUMN$$, “RECEPTION-HALFDAY-MAN”, “P2HD”)
replace($$CURRENTCOLUMN$$, “PRE1-FULLDAY-MAN”, “P1FD”)
replace($$CURRENTCOLUMN$$, “PRE1-MAN”, “P1HD”)
replace($$CURRENTCOLUMN$$, “PRE2-MAN”, “P2HD”)
replace($$CURRENTCOLUMN$$, “PRE3-MAN”, “P3HD”)
replace($$CURRENTCOLUMN$$, “NURSERY-HALFDAY-MAN”, “P1HD”)
replace($$CURRENTCOLUMN$$, “NURSERY-FULLDAY-MAN”, “P1FD”)

Is there a way to combine? Please help.

Thank you.

Are you using column loop nodes?

@aidel_realkids
you need to use replace( ) in string manipulation

image

image

replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace($column0$, "PRE1-ENG", "P1HD"), "PRE1-FULLDAY-ENG", "P1FD"), "PRE2-ENG", "P2HD"), "PRE2-FULLDAY-ENG", "P2FD"), "PRE3-ENG", "P3HD"), "PRE3-FULLDAY-ENG", "P3FD"), "PRE3-FULLDAY-MAN", "P3FD"), "REALTOTS Full Day", "TotFD"), "NURSERY-FULLDAY-ENG", "P1FD"), "NURSERY-HALFDAY-ENG", "P1HD"), "PRE-JUNIOR-FULLDAY-ENG", "P3FD")

replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace($necolumn$, "PRE-JUNIOR-HALFDAY-ENG", "P3HD"), "PRE-NURSERY PLUS-HALFDAY", "PNHD"), "RECEPTION-FULLDAY-ENG", "P2FD"), "RECEPTION-HALFDAY-ENG", "P2HD"), "PRE-JUNIOR-FULLDAY-MAN", "P3FD"), "PRE-JUNIOR-HALFDAY-MAN", "P3HD"), "REALTOTS Half Day", "TotHD"), "RECEPTION-FULLDAY-MAN", "P2FD"), "RECEPTION-HALFDAY-MAN", "P2HD"), "PRE1-FULLDAY-MAN", "P1FD"), "PRE1-MAN", "P1HD"), "PRE2-MAN", "P2HD"), "PRE3-MAN", "P3HD"), "NURSERY-HALFDAY-MAN", "P1HD"), "NURSERY-FULLDAY-MAN", "P1FD")

You can use like this to replace your columns.

Thank you… I manage to do it.

Thank you again.

1 Like

Hi @aidel_realkids,

if you want to fully substitute a a string (like, from “PRE1-ENG” to “P1HD”) I suggest you use Joiner node. Instead of writing 30+ lines of replace(…, “this”, “with that”), where if you have to add a value you need to manually input the new replace(), you can use a joiner to substitute an old value with a new one. See the attached workflow.

If you had fewer values (let’s say 3-5 and stable) I would have used a rule engine, because it’s easier to interpret lines.

Have a nice day,
Raffaello Barri

1 Like

Hi,

String Replacer (Dictionary) – KNIME Community Hub could be another option. Especially, if you already have the search patterns and replacement strings in a table.

5 Likes

String replace dictionary I think this node is the best approach and joiner has second. (like nan explained)

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