# Replace a char in a String

**URL:** <https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507>\
**Category:** Ignition\
**Created:** [December 14, 2020, 6:04pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507 "2020-12-14T18:04:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric.avila](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@eric.avila](https://forum.inductiveautomation.com/u/eric.avila)\
**Post date:** [December 14, 2020, 6:04pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507/1 "2020-12-14T18:04:27Z")

</div>

Hi,

I feel this is to simple but i can`t remove a char of a String.

i tried to use “replace” , but Ignition sends me an error “replace is not defined”,

i put this in an event and a script and is the same error.

this is my code: replace(MyString, anychar , “”)

i forgot something?

thanks

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 14, 2020, 6:04pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507/2 "2020-12-14T18:04:56Z")

</div>

Where are you trying to do this?

Are you trying to write Jython code or an expression?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 14, 2020, 6:09pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507/3 "2020-12-14T18:09:50Z")

</div>

```auto
MyString.replace(anychar,'')

```

```auto
myString = 'TestxString'
print myString.replace('x', ' ')

```

```auto
Test String

```

---

<div class="post-metadata">

**Author:** ![eric.avila](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@eric.avila](https://forum.inductiveautomation.com/u/eric.avila)\
**Post date:** [December 14, 2020, 6:11pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507/4 "2020-12-14T18:11:28Z")

</div>

tried to inside of an event in a button.  
after tried in a script and i call the script inside the event of the button

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [December 14, 2020, 6:23pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507/5 "2020-12-14T18:23:31Z")

</div>

As @dkhayes117 example shows, `replace` is a method on the string, not a standalone command.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [December 14, 2020, 7:32pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507/6 "2020-12-14T19:32:00Z")

</div>

Don’t forget you can use the script console under tools. I sometimes find it easier to play around in the console rather than in a window or in a component.

[https://docs.inductiveautomation.com/display/DOC80/Script+Console](https://docs.inductiveautomation.com/display/DOC80/Script+Console)

---

<div class="post-metadata">

**Author:** ![eric.avila](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@eric.avila](https://forum.inductiveautomation.com/u/eric.avila)\
**Post date:** [December 14, 2020, 8:38pm UTC](https://forum.inductiveautomation.com/t/replace-a-char-in-a-string/41507/7 "2020-12-14T20:38:16Z")

</div>

thanks, i solved my problem.

Thanks kevin.Herron and witman
