String manipulation function based on a condition

Hi Team,

I’m trying to do a string manipution based on a condition, I downloaded the Column Expresions to do it but unfortunately I haven’t resolved the trouble. The situation is something like this:

IF (column(“TpId”)=“A” THEN substr(column(“ID”),0,9)
ELSE (other value diferent to “A” for column “TpId” = “ID”)
The idea is to replace the values in column “ID” according to the condional

I appreciate any help even with another suggested node.

Hi @odiaz2309

Welcome to the KNIME Community. I think you are looking for something like this in the Column Expression:

if (column("TpId").equals("A")) {
    substr(column("ID"),0,9)
} else {
    column("ID")
}

This takes the 0 to 9 substring of ID whenever TpId is equals to A and otherwise keep the ID.

Please note: When posting a question in the forum, please include input and expected output, screenshots, (anonymized) data set, workflows, etc. as much as possible. To more you provide, the more accurate people can help you :wink:

2 Likes

Thank you so much, it works very well. I’ll take in count your suggestion

Hi @odiaz2309 and welcome to the Knime Community.

Another suggestion is to mark as Solution, the post that you accepted as solution, so other people can easily find the solution :smiley:

3 Likes