replace with java snippet

Hi guys,

i would like to use the Java snippet node to replace some values in a column for example: gmbhcokg should be replace with gmbh and co kg. the Problem is that i would like to replace more than one with that: gmbhcokg, gmbh&cokg, gmbh co kg and so on should be all replaced with gmbh and co kg. the Problem that i have is that i have used more than one Java snippet but is there a way to directly Code it?

Thanks,
Canan

No doubt there is a way to code it in Java, but I think a Cell Replacer node is an easier way to solve this problem, as you can replace multiple strings in one go.

2 Likes

Hi @Aswin

thank you for that. But i forgot to Mention that i dont want to replace the whole cell, for example Canan Limited should be replaced as Canan ltd.

Do you know another way how i can solve this?

Thanks,
Canan

Look at Column Expression node. It has a slew of string manipulation functions.

1 Like

Indeed a Cell Replacer will probably not work here.

There may be easier methods, but here is one way to solve the problem:
image

KNIME_project3.knwf (16.2 KB)

1 Like

hi @Aswin,

thank you so much, this helped me a lot :slight_smile:

Hi Canan

maybe this also works.

if(c_TEXT.indexOf(ā€œgmbhcokgā€)>=0) {out_TEXT = c_TEXT.replace(ā€œgmbhcokgā€, ā€œgmbh & co. kgā€);}
else if(c_TEXT.indexOf(ā€œgmbh&cokgā€)>=0) {out_TEXT = c_TEXT.replace(ā€œgmbh&cokgā€, ā€œgmbh & co. kgā€);}
else if(c_TEXT.indexOf(ā€œgmbh co kgā€)>=0) {out_TEXT = c_TEXT.replace(ā€œgmbh co kgā€, ā€œgmbh & co. kgā€);}
else out_TEXT = c_TEXT;

1 Like

Thank you @Morpheus,

this helped me also a lot.

Kind regards,
Canan

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