Discuss Scratch

donutty1
Scratcher
36 posts

if (item () in list) contains ()

I've tried loads of things but i can't try to find a way which i can have a block like this:

item...oflistcontains...?

it basically checks if an item (string) in a list contains a substring

which the output would be in a variable which stores either true or false, I'd be extremely grateful to anyone who helps!
RokCoder
Scratcher
1000+ posts

if (item () in list) contains ()

Something like (or based on) this should do the trick:

defineDoesstringcontainsubstringsetcontains substring?tofalseseti1to1repeatlengthofstring-lengthofsubstring+1seti2to1repeatuntilnotletteri2ofsubstring=letteri1+i2-1ofstringchangei2by1ifi2>lengthofsubstringthensetcontains substring?totruestopthis scriptchangei1by1
donutty1
Scratcher
36 posts

if (item () in list) contains ()

RokCoder wrote:

Something like (or based on) this should do the trick:

defineDoesstringcontainsubstringsetcontains substring?tofalseseti1to1repeatlengthofstring-lengthofsubstring+1seti2to1repeatuntilnotletteri2ofsubstring=letteri1+i2-1ofstringchangei2by1ifi2>lengthofsubstringthensetcontains substring?totruestopthis scriptchangei1by1

thanks so much! it works perfectly! really appreciate the help
smileycreations15
Scratcher
1000+ posts

if (item () in list) contains ()

donutty1 wrote:

I've tried loads of things but i can't try to find a way which i can have a block like this:

item...oflistcontains...?

it basically checks if an item (string) in a list contains a substring

which the output would be in a variable which stores either true or false, I'd be extremely grateful to anyone who helps!
scratch 3.0 it has a boolean for this purpose in the operators section.

Powered by DjangoBB