Hi @jarviscampbell , and welcome to the Knime Community.
Just be aware that the solutions provided by @elsamuel and @duristef are a bit different from what the replace() function would do, and they could well be actually the behaviour that you are looking for. But since you did not provide any sample data and your expected output for the sample data, it’s impossible to tell which behaviour you want.
By the way, an alternative to what they have provided would be to use the Rule Engine where you can add all your rules in that same node:
$color$ = "blue" => "azul"
$color$ = "red" => "vermelho"
$color$ = "green" => "verde"
TRUE => $color$
Pointing our the difference, and to keep it simple, let’s look at replacing “blue” with “azul”:
With the proposed solution, it will “replace” only if the value of the cell is just and only “blue”, while the replace() function would also do this replacement, but also would replace “blue” as part of a string, or as a substring of a word.
For example, this would be the expected output for these input data:
ID |
Input data |
Proposed solutions |
Replace() |
1 |
blue |
azul |
azul |
2 |
blue sky |
blue sky |
azul sky |
3 |
bluefins |
bluefins |
azulfins |
As you can see, only the record with ID 1 would be modified with the Proposed solutions, while all the records containing “blue” would be modified with Replace()
Of course, there are ways to also control what we want to replace, especially if you use regex - for example, you may want to replace “blue” only if it’s a word on its own (ID 1 and 2). Only a form of replace() can allow you to do this.
So it all depends on what behaviour you want. If you want to change only if the cell’s value is exactly “blue” (or “red”, or “green”), then one of the proposed solutions will work. But if you want “blue” (or “red”, or “green”) to be replaced as you wanted when you used the replace() function, then you have to use some form of replace() (replace() or regexReplace(), etc).
There are a few ways to do the replace() properly. You can do nested replace(), you can even do replace with if statements in Column Expressions. But first, let us know what is the behaviour you are looking for.