Character replacement in the string at position

Someone will advise.
I have text e.g. "101".
I want to change the character in 2 positions to "1" ... so that the text "111" is created. Or similar combinations in the 1st or 3rd position.
Do I have to do this by combining text and list functions?
Or is there an easier solution?

Maybe you could use dictionary blocks

Well thank you !!!

@dora_paz the result of the variable global name is in dictionary form and he is point somthing like "101" replace char at 2 to "1" then it would be "111" string form.

What you think if we add new built-in block for replace char at?

1 Like

Actually this is one way to achieve it

I had these BASIC(TM) flavored procedures in stock:
text.aia (18.0 KB) replace$ mid$ replace$_test

Those were written before we had the JOIN WITH SEPARATOR block, which could probably be used with the SPLIT AT '' block to make a shorter version.

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme
for a demo.

Here is an alternate version using the split and join with separator technique I mentioned in a prior post:
text.aia (20.0 KB)


P.S. The index + 1 for the replacement is because SPLIT AT '' adds an extra empty item at slot 1 of its output list. The empty item is swallowed up by the subsequent JOIN WITH SEPARATOR '' block.

If I use this procedure like this:blocks(46)

So the result should be 101, but he is 10.
Where did I make a mistake?

1 Like

Try with this

The two empty text blocks are empty!

You did not make a mistake.

You found a bug in my mid$ procedure.

Thanks for the bug alert!

Here are the corrected blocks ...
text.aia (20.6 KB)


I don't have access block Do .... result .. How to add it to the app?
Or how to copy the whole example to the app?


One way is from provided aia copy blocks to backpack and paste them in your project

But I don't have it in aia. These are the blocks from TIMAI2 ....

Then you have to replicate them because they are not dragable

I'm sorry, but somehow I don't understand ....

Let me make it easier for you. The below blocks are draggable into your project:


It works for me!
Well thank you !

Just continuing with the code base provided here by @TIMAI2 in previous post, to have support for insertCharAt and removeCharAt.

Having analyzed the output of code below


It is looking to be related to the concepts of Power Set where we are just looking for 1 element subset(s) and 0 element subset as we are trying to split the string with empty string.

1 Like