how to have multiple replace statements when using String manipulation

Hi @ivy_wang , welcome to the KNIME community.

The string manipulation node cannot accept multiple statements in the sense that they execute one after the other but it is possible to combine some statements together by “nesting” them,

e.g.

replace(
   replace($Column1$, "b", "bb"),
$Column1$, "a", "aa")

However this would have the effect of performing multiple replacements on strings like this:
image

I don’t know if that is what you want, but if it is then that’s great! :wink:

An alternative can be achieved using this syntax:

string(
$Column1$.equals("a")
?"aa"
:$Column1$.equals("b")
?"bb"
:$Column1$
)

which reads as "if Column1 =“a” then return “aa”, otherwise if Column1 = “b”, return “bb” otherwise return the value unchanged.

(and you could also place commands such as replace() instead of literals such as “aa” or “bb” )

The result would be:
image

1 Like