Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to remove a letter from a string?
- peterjhc
-
43 posts
How to remove a letter from a string?
So, I'm trying to make … remove the first letter of a specified item in a list, unless the first letter is O.
Anyone know how to make this?
Last edited by peterjhc (Sept. 9, 2015 19:24:25)
- deck26
-
1000+ posts
How to remove a letter from a string?
You can't easily remove individual characters from a string, you have to rebuild the string without the character.
- peterjhc
-
43 posts
How to remove a letter from a string?
Hmm… You can't easily remove individual characters from a string, you have to rebuild the string without the character.
Can you take a look at this project and perhaps tell me what kind of script to do? It would really help.

Last edited by peterjhc (Sept. 9, 2015 19:33:02)
- deck26
-
1000+ posts
How to remove a letter from a string?
So to move left you'd have to create another string, copy all but the first letter of the old string to the new one and then replace the old string with the new one.
Going up and down is easier as you can potentially swap items - but not if you're going to make the items more complicated which I guess you are.
You'll probably need to use custom blocks with no screen refresh for speed.
Going up and down is easier as you can potentially swap items - but not if you're going to make the items more complicated which I guess you are.
You'll probably need to use custom blocks with no screen refresh for speed.
- peterjhc
-
43 posts
How to remove a letter from a string?
Could I do something along the lines of So to move left you'd have to create another string, copy all but the first letter of the old string to the new one and then replace the old string with the new one.
Going up and down is easier as you can potentially swap items - but not if you're going to make the items more complicated which I guess you are.
You'll probably need to use custom blocks with no screen refresh for speed.
Or would I have to use a different block to get rid of the item?
If so, would you mind doing a Scratchblocks thing for it?

I don't know why the item 14 of List isn't loading right.
Last edited by peterjhc (Sept. 9, 2015 19:51:06)
- deck26
-
1000+ posts
How to remove a letter from a string?
No, as I've already said there is no easy way of removing a letter from a string. The minus is an arithmetic operation so would only have any effect if the list item could be converted to a number and then it wouldn't give you what you want.
- monstermash3
-
1000+ posts
How to remove a letter from a string?
Try:
Last edited by monstermash3 (Sept. 10, 2015 00:14:18)
- scarlett10
-
2 posts
How to remove a letter from a string?
anything that can be done inside 5 minuets❔
- monstermash3
-
1000+ posts
How to remove a letter from a string?
That script wouldn't take that long… Really, it's just saying: anything that can be done inside 5 minuets❔
If the first letter of the item of the list is not an O, reset the variable used to put together the rest of the string to 2 (since the first letter will be skipped), set another to the current item string since it will be replaced, replace the item with nothing, then, to put the rest back together, repeat the following the length of the second variable minus one (since the first will be skipped): add the letter that the first variable is set to to the end of the item by replacing it with the current item joined to the letter, and change the first variable by 1 for the next frame…
- deck26
-
1000+ posts
How to remove a letter from a string?
The coding is not difficult but if you want the project to work the way it is (so each list item represents a row in the game) you have no option but rebuild the string. How simple that is depends on how variable the contents of the string are.
All very doable with custom blocks though.
All very doable with custom blocks though.
- peterjhc
-
43 posts
How to remove a letter from a string?
Okay, I tried this. It didn't do anything. Is something in the scratchblocks hidden by the page? Try:
- monstermash3
-
1000+ posts
How to remove a letter from a string?
The “replace item (put number here) of list with (join (item (put number here) of list) (letter (variable) of (anothervariable)))” stretches a bit off the page.Okay, I tried this. It didn't do anything. Is something in the scratchblocks hidden by the page? Try:
This is a pretty complex script, so maybe I did leave something out.
Last edited by monstermash3 (Sept. 10, 2015 23:15:17)
- peterjhc
-
43 posts
How to remove a letter from a string?
Maybe… I'll leave this topic open for a day or two for new comments, and after that, I'll close the topic and use @deck26's script.The “replace item (put number here) of list with (join (item (put number here) of list) (letter (variable) of (anothervariable)))” stretches a bit off the page.Okay, I tried this. It didn't do anything. Is something in the scratchblocks hidden by the page? Try:
This is a pretty complex script, so maybe I did leave something out.
- monstermash3
-
1000+ posts
How to remove a letter from a string?
Maybe… I'll leave this topic open for a day or two for new comments, and after that, I'll close the topic and use @deck26's script.The “replace item (put number here) of list with (join (item (put number here) of list) (letter (variable) of (anothervariable)))” stretches a bit off the page.Okay, I tried this. It didn't do anything. Is something in the scratchblocks hidden by the page? Try:
This is a pretty complex script, so maybe I did leave something out.
That's basically exactly what that script does. So to move left you'd have to create another string, copy all but the first letter of the old string to the new one and then replace the old string with the new one.
- Piguthew
-
1 post
How to remove a letter from a string?
Anyone got a really basic version for someone thats new to Scratch?
- deck26
-
1000+ posts
How to remove a letter from a string?
Please create your own new topic rather than necroposting. Anyone got a really basic version for someone thats new to Scratch?
Rebuilding a copy of a string to remove one character does unfortunately mean going through the string character by character so you have to understand loops.
However there is potentially an easier option using a list.
Clear the list
Loop through your text letter by letter. If you want to keep the letter add it to the list, otherwise ignore it.
At the end of the loop set a variable equal to the list.
This makes use of the fact that Scratch will assign a list of single characters to a variable by just joining them all together as one string. As soon as any of the list entries is longer this will fail because Scratch will add spaces between the list entries.
- SkyGuy354
-
19 posts
How to remove a letter from a string?
well, I wanna Do It But Leave The O In
- komattlee01
-
5 posts
How to remove a letter from a string?
It's actually not as monstrously big if it's to do with numbers, which I know it isn't, but anyway you could have a string to integer script like this.
etc.
Now to my idea.
as you can now tell, by simply dividing it by ten, the right most column has been put into decimals, and chopped off. Hope it helped. (Highly doubt it did, just felt like sharing.
)
etc.
Now to my idea.
as you can now tell, by simply dividing it by ten, the right most column has been put into decimals, and chopped off. Hope it helped. (Highly doubt it did, just felt like sharing.

- DUYdeptrai2019
-
93 posts
How to remove a letter from a string?
Reporting to be closed to prevent necroposting
- Discussion Forums
- » Help with Scripts
-
» How to remove a letter from a string?