Replace a string in Java based on a column

Hi there I am trying to replace some values of a column (A) using another column (B) based a reference column (REF C). I was tying using java, but I have an error.  

This what I want.

ROW ID COLUMN A COLUMN B REF C NEW COLUMN A
1 OLD VALUE NEW VALUE REPLACE NEW VALUE
2 SAME VALUE SAME VALUE NOT REPLACE SAME VALUE
3 OLD VALUE NEW VALUE REPLACE NEW VALUE
4 SAME VALUE SAME VALUE NOT REPLACE SAME VALUE
5 OLD VALUE NEW VALUE REPLACE NEW VALUE

The code is the following:

if (c_REFC.equals("REPLACE")) {
    c_COLUMNA=c_COLUMNA.replace(c_COLUMNB);
} else {
   c_COLUMNA=c_COLUMNA;
}

 

I know that the above table is asking to add a new column, but I need is to replace some values.

Best regards

 

 

This looks like a perfect match for the Rule Engine node.

Hi thor thank you for the help, but I applied that node and got a lot of missing values "?".

The rule that I applied was:

$REF C$ = "REPLACE"=>$COLUMN B$

and used the option Replace Column "COLUMN A"

and this is the result:

ROW ID COLUMN A COLUMN B REF C NEW COLUMN A
1 OLD VALUE NEW VALUE REPLACE NEW VALUE
2 SAME VALUE SAME VALUE NOT REPLACE ?
3 OLD VALUE NEW VALUE REPLACE NEW VALUE
4 SAME VALUE SAME VALUE NOT REPLACE ?
5 OLD VALUE NEW VALUE REPLACE NEW VALUE

Means that when REF C does not meet the condition replaces a "?" in column A.

Is there another option?

Thank you

 

 

 

You should also add $REF C$ = "NOT REPLACE"=>$COLUMN A$, so the rules should look like this:

$REF C$ = "REPLACE"=>$COLUMN B$
$REF C$ = "NOT REPLACE"=>$COLUMN A$

Cheers, gabor

PS: in this case the order of rules does not matter, you could add the new rule before the other one. In case you prefer the results to be in NEW COLUMN A, uncheck the replace column option.

Hi Thor I made a change in the rule and worked.

 

$REF C$ = "REPLACE" OR $COLUMN A$ = $COLUMN B$=>$COLUMN B$

 

Thank you