Discuss Scratch

Slimmmmmmmmm
Scratcher
20 posts

How to delete a letter of a word/variable/item of a list etc

Ok I will tell you how to make a script that can delete a letter of a word/variable/item of a list etc.
Step1
Create a variable called Output
(Output)
This is where the output is going to go to. Also create a list called letters.
(Letters :: list)
This is a list where all the letters will get split up.
Create another variable called numbers
(numbers)
I can't explain what it does but you have to create this variable.
Step 2
Create this script
define Delete letter (letter) of (input)
set [number v] to [0 ]
delete [all v] of [Letters v]
set [output v] to [ ]
This will clear out everything when you use this script.
Step 3
Add the repeat script to the script.
define Delete letter (letter) of (input)
set [number v] to [0 ]
delete [all v] of [Letters v]
set [output v] to [ ]
repeat (length of (input))

change [number v] by (1)
add (letter (number) of (input)) to [Letters v]
end

This will split up the letters in the input.
Step 4
Add The delete and repeat script to it and your done.
define Delete letter (letter) of (input)
set [number v] to [0 ]
delete [all v] of [Letters v]
set [output v] to [ ]
repeat (length of (input))
change [number v] by (1)
add (letter (number) of (input)) to [Letters v]
end
delete (letter) of [Letters v]
set [number v] to [0]
repeat (length of [Letters v] ::list)
change [number v] by (1)
set [output v] to (join (output) (item (number) of [Letters v])
end
Thanks for viewing this tutorial! Also what it will return is this
Delete letter (1) of []::custom

Last edited by Slimmmmmmmmm (April 2, 2016 02:11:29)

deck26
Scratcher
1000+ posts

How to delete a letter of a word/variable/item of a list etc

Note that the idea of the forum is for people to ask for help, not for tutorials.

I think this can be done more simply.

Clear a temporary variable. Create a loop that runs from 1 to n (the length of the input). The index value for that loop is compared to the number of the letter to be removed and if it matches you don't add that letter but if it doesn't match you do add it.

set [tempword v] to [ ]
set [indx v] to [1 ]
repeat (length of [input])
if <[indx v] = [letter v ]> then
set [tempword v] to (join [tempword v] (letter (indx) of [input])
end
change [index v] by (1)
end
set [input v] to (tempword )
If you want to do this in a custom block you'd need the output variable as used in your scripts as you can't pass back a change to input.
PrizmGames
Scratcher
56 posts

How to delete a letter of a word/variable/item of a list etc

delete ((position)) of ((variable))
change [(position) v] by (0)

Last edited by PrizmGames (Jan. 22, 2016 13:47:16)

BKFighter
Scratcher
1000+ posts

How to delete a letter of a word/variable/item of a list etc

PrizmGames wrote:

delete ((position)) of ((variable))
change [(position) v] by (0)
Please do not necropost, as this topic was last used over a year ago.
redmadd
Scratcher
2 posts

How to delete a letter of a word/variable/item of a list etc

.

Last edited by redmadd (Aug. 23, 2023 00:56:20)

Powered by DjangoBB