Nested string functions

Hello

I’m trying to build - what I think is - a complex string function and I’m strugging.

From a string, I want to cut out a part of it in the middle.

What I would like to do is something like this:

originalString = “Apple, Banana, Pear, Peach”;
toRemove = “Banana”;
start = originalString.indexOf(toRemove);
left = originalString.slice(0, start);
right = originalString.slice(start + toRemove.length);
result = left.concat(right);

Let’s say, I want this to work on the click of a button, which updates the text on a box.

In Interactions I use: OnClick -> setText

And I’m stuck. There’s only one field there. Of course, all of this can be combined into one complex phrase:

[[originalString.slice(0, originalString.indexOf(toRemove)).contact(originalString.slice(originalString.indexOf(toRemove) + toRemove.length))]]

The problem is, that this is not working.

Please check the uploaded file and let me know what am I doing wrong?

Thank youtmp.rp (47.7 KB)

You misspelled concat as contact so I’d try correcting that first and see if it works.

That said, it might be easier to just use replace:

originalString.replace(toRemove','')

You could also add .replace(',,',',') in case you end up with a double comma from removing something in the middle of the list.

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