Removing just one character in a text string

Hi everyone!

I was looking for clues all around this community and MIT app inventor forum, and i haven’t found any useful clue for my doubt, or just the topic is closed.
Sorry if didn’t look for it well

From a text string, for several times, it’s about to get only one random character, and only the picked one has to be removed from the string

Let’s suppose the string NORTHEASTSOUTHWEST (no spaces nor commas…)
It’s selected by random the character S (placed in South)
Now the string should remain as NORTHEASTOUTHWEST
And then several times more…

I do the random selection by ‘random integer from 1 to length…’ block to pick one character using the ‘segment text start length’ block
But, how i do the second part? I have been watching around there for a long time how to use replace all text, but it’s not about replacing all the S around the text, or the other text blocks as trim, segment, split and so… but i can’t imagine or find up the right steps…

So thanks in advance!

Can You Share Your Blocks
Images What you Have tried So Far

Hi
i use something like that, take a look if work for you

Try this way

image

2 Likes

Or this:

2 Likes

I believe still there is an issue with split at an empty separator depending android version ≤ 9 or ≥ 10. If android version is ≤ 9 then an empty string is added in the beginning of list and that is the reason I added a check (list’s lenght and text lenght). Otherwise if random number is 1 and android version ≤ 9 the result will be the same word I believe

1 Like

Right. I forgot, thought it was only with AI2.

3 Likes

Hi again!

Many thanks for your answers! Your tips are right for me, I’ve learnt a lot from them!
So, I’m now trying to do your tips
But, in the meanwhile, i’d like to know your tips about the second and next times to do the next selection and removing, i just need a clue, no need blocks (of course, if so, i’d thank it)

Thanks in advance again!

Clean and polished, far away better from my option xD

Hi again!

I’ve tryed the Anke’s tip, but it doesn’t work
Is it not global list a list with only one item?
Then how to remove list item index random… ?
So, it is showed a runtime error

Please, any light will be welcomed

You’re trying to remove an item from a global variable which is not a list.

Dismiss the error and post again a screenshot of your blocks because procedure is hidden

From what have read do you want to remove the letter “S” from NORTHEASTSOUTHWEST so as to get this NORTHEASTOUTHWEST?

The matter is in remove … random block, just under notification
Here you are

It’s about to remove only one (any) character by random from an initial string

At last i got it!

Thanks for all your tips cause they was useful clues.

1 Like

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