Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » alternative to `contains` block
- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
hi! i'm having a bit of trouble with my script, i'm trying to identify certain characters in a word and replace them with a symbol.
i have managed to do this by using the `contains` block but i was wondering if there is an alternative to this as i do not have a `contains` block in the version of scratch that i am required to use!
any help would be massively appreciated, i've been wracking my brain for nearly two weeks over this
i have managed to do this by using the `contains` block but i was wondering if there is an alternative to this as i do not have a `contains` block in the version of scratch that i am required to use!
any help would be massively appreciated, i've been wracking my brain for nearly two weeks over this

- medians
-
Scratcher
1000+ posts
alternative to `contains` block
Oh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
Oh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
thank you for the suggestion! unfortunately yes i'm constrained to 2.0

i have tried making a list with the characters i'd like to replace but my output is replacing the entire word with symbols as opposed to what i specified! just wondering if there's something i'm forgetting to add?
- deck26
-
Scratcher
1000+ posts
alternative to `contains` block
Are you perhaps looping through the word and forgetting to implement the control variable when you hit a character that needs replacing?
Last edited by deck26 (Jan. 11, 2023 13:54:27)
- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
Are you perhaps looping through the word and forgetting to implement the control variable when you hit a character that needs replacing?
it is very much possible, i am having a hard time understanding how things work in scratch which is what is impeding me in solving my problem. i'm not too sure how to go about how to implement the change to certain characters instead of returning a string that is all symbols.
- deck26
-
Scratcher
1000+ posts
alternative to `contains` block
In pseudo code what you probably need is something like
set newstring to blank
set index to 1
repeat until index > length of input
if letter (index) of input is in specified set append symbol to newstring
else letter index of input to newstring
increase index by 1
end
In Scratch 2 the list blocks DO have the contains block so that should be available to you and you can check if list contains letter(index) of input.
If you have no access to any contains block you'd need to have an inner loop that ran through all the letters that needed replacing until you either found a match or ran out of things to try. So for the letter you're checking you would know whether to use it or replace it but you'd have to repeat the inner loop for the next letter.
set newstring to blank
set index to 1
repeat until index > length of input
if letter (index) of input is in specified set append symbol to newstring
else letter index of input to newstring
increase index by 1
end
In Scratch 2 the list blocks DO have the contains block so that should be available to you and you can check if list contains letter(index) of input.
If you have no access to any contains block you'd need to have an inner loop that ran through all the letters that needed replacing until you either found a match or ran out of things to try. So for the letter you're checking you would know whether to use it or replace it but you'd have to repeat the inner loop for the next letter.
- medians
-
Scratcher
1000+ posts
alternative to `contains` block
…Yeah I think you offended every 2.0 person LOLOh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
thank you for the suggestion! unfortunately yes i'm constrained to 2.0
i have tried making a list with the characters i'd like to replace but my output is replacing the entire word with symbols as opposed to what i specified! just wondering if there's something i'm forgetting to add?
Anyway I think I got it:

The first repeat block just copies over all characters, and it just scans through the length of the 2nd string characters using an index, then checks if the string has the same length every time so it can end. And if it's equal to string2, then it contains it and you have to delete the first index to keep checking.
Last edited by medians (Jan. 11, 2023 14:13:03)
- deck26
-
Scratcher
1000+ posts
alternative to `contains` block
My impression is they're only replacing single characters with a symbol if they're in a specificied set rather than searching for a substring to replace.…Yeah I think you offended every 2.0 person LOLOh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
thank you for the suggestion! unfortunately yes i'm constrained to 2.0
i have tried making a list with the characters i'd like to replace but my output is replacing the entire word with symbols as opposed to what i specified! just wondering if there's something i'm forgetting to add?
Anyway I think I got it:
- cookieclickerer33
-
Scratcher
1000+ posts
alternative to `contains` block
My i ask why?Oh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
thank you for the suggestion! unfortunately yes i'm constrained to 2.0
i have tried making a list with the characters i'd like to replace but my output is replacing the entire word with symbols as opposed to what i specified! just wondering if there's something i'm forgetting to add?
(And if ur constrained to that please use Snap! if you can)
- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
My impression is they're only replacing single characters with a symbol if they're in a specificied set rather than searching for a substring to replace.…Yeah I think you offended every 2.0 person LOLOh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
thank you for the suggestion! unfortunately yes i'm constrained to 2.0
i have tried making a list with the characters i'd like to replace but my output is replacing the entire word with symbols as opposed to what i specified! just wondering if there's something i'm forgetting to add?
Anyway I think I got it:
yeah, that's more along the lines of what i'm hoping to do. not to discredit @medians work of course, i'm very grateful for their solution!
my solution so far contains a list of all the characters i wish to replace, and a loop which i am trying to get to ‘search’ the user-input word for any characters that need to be replaced, i have access to the list contains block but i don't think i am going the right way about actually replacing the specified letters if it's returning a string of symbols, or not actually recognising that a word contains one of the specified letters.
<[ v] contains [thing] ?>
- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
My i ask why?Oh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
thank you for the suggestion! unfortunately yes i'm constrained to 2.0
i have tried making a list with the characters i'd like to replace but my output is replacing the entire word with symbols as opposed to what i specified! just wondering if there's something i'm forgetting to add?
(And if ur constrained to that please use Snap! if you can)
it's for a project but the specified software we have to use is scratch 2.0 and not 3.0, i have no qualms with 2.0 i just can't wrap my head around this problem specifically!
- cookieclickerer33
-
Scratcher
1000+ posts
alternative to `contains` block
That’s stupid..My i ask why?Oh god you’re in 2.0, right?
Check this, but I don’t know if it will work at this point:
https://en.scratch-wiki.info/wiki/Checking_if_a_String_Contains_a_String
You could also probably find a way to put every character in a list and then check for 1-4 (if the length of the 2nd input is 4), then 2-5, then 3-6, etc, or something like this.
thank you for the suggestion! unfortunately yes i'm constrained to 2.0
i have tried making a list with the characters i'd like to replace but my output is replacing the entire word with symbols as opposed to what i specified! just wondering if there's something i'm forgetting to add?
(And if ur constrained to that please use Snap! if you can)
it's for a project but the specified software we have to use is scratch 2.0 and not 3.0, i have no qualms with 2.0 i just can't wrap my head around this problem specifically!
- cookieclickerer33
-
Scratcher
1000+ posts
alternative to `contains` block
Well you could do
define (1) contains (2)That for each block is a hidden block that works like
For each [counter v] in (length of (1::custom)){
if <(letter (counter) of (1::custom)) = (2::custom)> then
Set [return v] to [true]
Stop [this script v]
Else
Set [return v] to [false]
}::control
repeat (length of (1::custom))
change [counter v] by (1)
end
Last edited by cookieclickerer33 (Jan. 11, 2023 15:10:29)
- deck26
-
Scratcher
1000+ posts
alternative to `contains` block
my solution so far contains a list of all the characters i wish to replace, and a loop which i am trying to get to ‘search’ the user-input word for any characters that need to be replaced, i have access to the list contains block but i don't think i am going the right way about actually replacing the specified letters if it's returning a string of symbols, or not actually recognising that a word contains one of the specified letters.You need to do something like<[ v] contains [thing] ?>
<[list v] contains (letter (index) of (input)) ?>
Last edited by deck26 (Jan. 11, 2023 15:23:21)
- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
my solution so far contains a list of all the characters i wish to replace, and a loop which i am trying to get to ‘search’ the user-input word for any characters that need to be replaced, i have access to the list contains block but i don't think i am going the right way about actually replacing the specified letters if it's returning a string of symbols, or not actually recognising that a word contains one of the specified letters.You need to do something like<[ v] contains [thing] ?><[list v] contains (letter (index) of (input)) ?>
yeah, that's relatively similar to what i've been using so i'm not really sure where else i'm going wrong. here are my projects using the contains block vs not using it (the without contains block is what i'm trying to solve at the moment:
without `contains` block
with `contains` block
sorry if the solution ends up being something overlooked or massively trivial, i have no one to cast an eye over my work that would understand what i'm trying to do otherwise

- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
Well you could dodefine (1) contains (2)That for each block is a hidden block that works like
For each [counter v] in (length of (1::custom)){
if <(letter (counter) of (1::custom)) = (2::custom)> then
Set [return v] to [true]
Stop [this script v]
Else
Set [return v] to [false]
}::controlrepeat (length of (1::custom))
change [counter v] by (1)
end
thank you! i don't think i have access to
For each [counter v] in (length of (1::custom)){here is a link to what i am trying currently, if that gives you a better idea!

- deck26
-
Scratcher
1000+ posts
alternative to `contains` block
Look at how you're using (or not using!) index in the first version! You only ever refer to letter 1 of the input.my solution so far contains a list of all the characters i wish to replace, and a loop which i am trying to get to ‘search’ the user-input word for any characters that need to be replaced, i have access to the list contains block but i don't think i am going the right way about actually replacing the specified letters if it's returning a string of symbols, or not actually recognising that a word contains one of the specified letters.You need to do something like<[ v] contains [thing] ?><[list v] contains (letter (index) of (input)) ?>
yeah, that's relatively similar to what i've been using so i'm not really sure where else i'm going wrong. here are my projects using the contains block vs not using it (the without contains block is what i'm trying to solve at the moment:
without `contains` block
with `contains` block
sorry if the solution ends up being something overlooked or massively trivial, i have no one to cast an eye over my work that would understand what i'm trying to do otherwise
- cookieclickerer33
-
Scratcher
1000+ posts
alternative to `contains` block
It’s basic the same thing as increasing the variable at the start of each loopWell you could dodefine (1) contains (2)That for each block is a hidden block that works like
For each [counter v] in (length of (1::custom)){
if <(letter (counter) of (1::custom)) = (2::custom)> then
Set [return v] to [true]
Stop [this script v]
Else
Set [return v] to [false]
}::controlrepeat (length of (1::custom))
change [counter v] by (1)
end
thank you! i don't think i have access toFor each [counter v] in (length of (1::custom)){
here is a link to what i am trying currently, if that gives you a better idea!
- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
Look at how you're using (or not using!) index in the first version! You only ever refer to letter 1 of the input.my solution so far contains a list of all the characters i wish to replace, and a loop which i am trying to get to ‘search’ the user-input word for any characters that need to be replaced, i have access to the list contains block but i don't think i am going the right way about actually replacing the specified letters if it's returning a string of symbols, or not actually recognising that a word contains one of the specified letters.You need to do something like<[ v] contains [thing] ?><[list v] contains (letter (index) of (input)) ?>
yeah, that's relatively similar to what i've been using so i'm not really sure where else i'm going wrong. here are my projects using the contains block vs not using it (the without contains block is what i'm trying to solve at the moment:
without `contains` block
with `contains` block
sorry if the solution ends up being something overlooked or massively trivial, i have no one to cast an eye over my work that would understand what i'm trying to do otherwise
i'm afraid i'm not actually sure how to identify where i've made a mistake, i've been working off other scratchers' advice and previous worked examples

- laurensmiddy
-
New Scratcher
9 posts
alternative to `contains` block
update:
i decided to restart from the beginning instead of reworking scripts that already existed (i think this is where most of the confusion came from to be honest), i seem to have things working and running smoothly!
thank you to everyone who helped! sorry if the answer was hidden in plain sight and it was frustrating that i was completely missing it
(disclaimer: i am still jet lagged and sleep deprived so my brain is foggier than usual
)
best wishes
i decided to restart from the beginning instead of reworking scripts that already existed (i think this is where most of the confusion came from to be honest), i seem to have things working and running smoothly!
thank you to everyone who helped! sorry if the answer was hidden in plain sight and it was frustrating that i was completely missing it

(disclaimer: i am still jet lagged and sleep deprived so my brain is foggier than usual
)best wishes

- Discussion Forums
- » Help with Scripts
-
» alternative to `contains` block



