Replace a Letter in a String

So, like I say in the Title I need to replace a single letter in a String in a position; I have done it creating two substring before and after the position and then recreating a single string with the new letter in the middle (Ex: if I want to change the letter “t” of the String “antani” with “Y”, I create two String, “an” and “ani” and I join them with “Y” in the middle obtaining “anYani”)

The problem is that I need to use a counter and is easy to make a mistake that is difficult to find.
There isn’t a simpler way to do it like 1 simple Action?

It’s unclear where the counter comes into play and how that would make it easier to create mistakes. Can you elaborate?

My initial thoughts are to either us the regex extension, or us a javascript code event and do it in javascript.

1 Like

Yes, sorry, the counter is needed in the game that i am doing to arrive at the letter position… sorry, I said that wrong!

I have tried with the regex extension but I think it’s too complicate for me and I’m not good with javascript!

I wanted just to check if there was a simpler way to replace a part or a single letter of a string. Maybe something that I did not read.

You’ll be surprised how much you can do with a little googling.

Here’s how to do it in javascript :

1 Like

I think It’s too much complicated for me AFTER “a little googling” (that it’s the first thing I do when I have a problem :grin:)

Thanks for the Javascript!

This is how I have done it (with a String Expression):

In my project I may have to run it even ten thousand times or more every 0.1-0.2 seconds… do you think this method and your (with Java) can have different impact on the processing power, where your is faster?

There’s one way to find out - run a timed test over 100,000 or even 1,000,000 objects