# Replace string - n occurences

**URL:** <https://forum.inductiveautomation.com/t/replace-string-n-occurences/26796>\
**Category:** Ignition\
**Created:** [July 23, 2019, 1:11pm UTC](https://forum.inductiveautomation.com/t/replace-string-n-occurences/26796 "2019-07-23T13:11:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsowrirajan](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@rsowrirajan](https://forum.inductiveautomation.com/u/rsowrirajan)\
**Post date:** [July 23, 2019, 1:11pm UTC](https://forum.inductiveautomation.com/t/replace-string-n-occurences/26796/1 "2019-07-23T13:11:06Z")

</div>

Can the replace string expression function (for property binding) be configured to replace n occurences of a substring than a replaceall

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 23, 2019, 2:18pm UTC](https://forum.inductiveautomation.com/t/replace-string-n-occurences/26796/2 "2019-07-23T14:18:14Z")

</div>

A Quick glance at the documentation leads me to believe that the expression does not allow for anything other than “replace each occurrence of ‘some\_value’ with ‘some\_other\_value’”.

There are always other avenues to accomplish what you’re looking to do. have you tried using [runScript](https://docs.inductiveautomation.com/display/DOC80/runScript) ? You could supply your own function to perform the ‘n-occurences’ logic as applied to a supplied string argument.

```auto
runScript(project.myScript.replaceFirstNOccurences, args={'my_str': "banana", 'replace_this_text': "a", 'with_this': "i", 'n_occur': 2})

```

Project script:

```auto
def replaceFirstNOccurences(my_str, replace_this_text, with_this, n_occur):
    return str(my_str).replace(replace_this_text, with_this, n_occur)

```

The provided expression/script combo should return “binina”.
