# replace with java snippet

**URL:** <https://forum.knime.com/t/replace-with-java-snippet/15265>\
**Category:** KNIME Analytics Platform\
**Created:** [May 22, 2019, 12:14pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265 "2019-05-22T12:14:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon33357744](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/cc9497/32.png) [@anon33357744](https://forum.knime.com/u/anon33357744)\
**Post date:** [May 22, 2019, 12:14pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/1 "2019-05-22T12:14:42Z")

</div>

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?

 ![image](https://forum-cdn.knime.com/uploads/default/original/2X/7/76f98e9c6c23a647efe766a342925430d95db3fe.png)

Thanks,  
Canan

---

<div class="post-metadata">

**Author:** ![Aswin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/aswin/32/3344_2.png) [@Aswin](https://forum.knime.com/u/Aswin)\
**Post date:** [May 22, 2019, 12:41pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/3 "2019-05-22T12:41:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon33357744](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/cc9497/32.png) [@anon33357744](https://forum.knime.com/u/anon33357744)\
**Post date:** [May 22, 2019, 1:35pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/4 "2019-05-22T13:35:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![izaychik63](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/i/e9a140/32.png) [@izaychik63](https://forum.knime.com/u/izaychik63)\
**Post date:** [May 22, 2019, 1:43pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/5 "2019-05-22T13:43:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aswin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/aswin/32/3344_2.png) [@Aswin](https://forum.knime.com/u/Aswin)\
**Post date:** [May 22, 2019, 2:03pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/6 "2019-05-22T14:03:45Z")

</div>

Indeed a Cell Replacer will probably not work here.

There may be easier methods, but here is one way to solve the problem:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/2X/b/b39d43c2cd909a73b38212b8a12da1ab27683f6b.png)

[KNIME\_project3.knwf](https://forum-cdn.knime.com/uploads/default/original/2X/2/243bb685332e60562cf05723ef2d7b1cc1497b3a.knwf) (16.2 KB)

---

<div class="post-metadata">

**Author:** ![anon33357744](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/cc9497/32.png) [@anon33357744](https://forum.knime.com/u/anon33357744)\
**Post date:** [May 22, 2019, 3:46pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/7 "2019-05-22T15:46:16Z")

</div>

hi @Aswin,

thank you so much, this helped me a lot 🙂

---

<div class="post-metadata">

**Author:** ![morpheus](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/ce73a5/32.png) [@morpheus](https://forum.knime.com/u/morpheus)\
**Post date:** [May 23, 2019, 5:20am UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/8 "2019-05-23T05:20:21Z")

</div>

Hi Canan

maybe this also works.

 ![screenshot](https://forum-cdn.knime.com/uploads/default/original/2X/7/7b41a9d7c7c1b837bdfaa2da89111abd816bef03.png)

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;

---

<div class="post-metadata">

**Author:** ![anon33357744](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/cc9497/32.png) [@anon33357744](https://forum.knime.com/u/anon33357744)\
**Post date:** [May 23, 2019, 12:00pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/9 "2019-05-23T12:00:42Z")

</div>

Thank you @Morpheus,

this helped me also a lot.

Kind regards,  
Canan

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 30, 2019, 12:00pm UTC](https://forum.knime.com/t/replace-with-java-snippet/15265/10 "2019-05-30T12:00:42Z")

</div>

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