Add <[string1] contains [string2]?:: operators>

Can you please add this block:
[scratchblocks]
<[string1] contains [string2]?:: operators>
[/scratchblocks]
It is in Scratch 3.0 and it would be useful if it's used on this programming language.

how would this be useful though?

It would be useful for bad word detectors, whether input contains a certain string, stuff like that.

And what projects would people use these for?

I dunno. Maybe for animal guessing games?

Why won't you make it yourself?

Well, I tried recreating that block on this programming language but failed. Can you try recreating that block?

if it can be made by the person who programmed that block in scratch 3.0 in javascript, it can be made in snap, so i'll try

(or if the person used a built-in javascript function, then the person that made the browser's javascript interpreter)

Ok, I made it, and it's pretty simple:

It goes through each letter of str1 and checks if the letter is equal to the first letter of str2. If it is, it checks if the next letter of str1 is the second letter of str2. Then it checks if the next letter of str1 is the third letter of str3, and so on. If it reached the end of str2 then it means it has found a match.

Put it in a
[scratchblocks]
warp {
} ::grey
[/scratchblocks]
block and you're solid

I've made this block before, CONTAINS block for text strings that's my simplest version, but the block is in the strings, multiline input library.

Very elegant!

lol, you should've seen my second attempt (the first was case sensitive, but the second wasn't)

I think your version fails on overlapping substrings. For example, I want to know if the string "salaaami" contains the string "aam"; when you see the second "a" you move on to the next letter of str1, which matches the second letter of str2, so you go on to the next letter of str1, which doesn't match the third letter of str2. So you reset ltr to 1, and move on to the next letter of str1, which is the fourth and last "a", so you can't match "aam" with the remaining letters.

The library version uses the JS primive. It's doable entirely in Snap!, but doing it right requires two nested loops, one of which finds a matching first letter and the inner one then checks for the rest of the desired substring.

And that's the answer to the original request. Look for [scratchblocks]< text contains ::operators>[/scratchblocks] in the "Strings, Multiline inputs" library :slight_smile:

What about converting, using snapinator, a project that uses []contains[] and see what happens?

It causes it to turn into a gray block that says something like
"UNSUPPORTED: operators_contains"

Picture:
image

Ah, ok.

I haven't checked the lib, or anyone elses' libraries but heres a super simple one.

[scratchblocks]
<(string1) contains (string2) ?::operators>:: hat control
report <(Length of (Split(string1) by(string2)::operators)::list) > (1) ?::operators>:: control cap
[/scratchblocks]