CONTAINS block for text strings

Very elegant!

Yes. I just wanted his solution to have a separate topic. That's why I suggested to make a split because the initial title doesn't mention it at all.

Oh I see.

Actually I was thinking of adding those blocks to the strings library. Is that okay, @ego-lay_atman-bay?

1 Like

sure

I ended up doing it in JS after all, so I could use the flag set by USE CASE-INDEPENDENT SEARCH, which is in the world's JS variables because at the time we didn't have the Variables library. I may rethink that, now that we do have it.

uh... can you explain that like you're talking to a five year old (note, I am not 5 years old, I know a lot more stuff than 5 year olds do)

I don't understand, either.

Why don't you add a block to convert strings to uppercase strings, too? You could use JavaScript's toUpperCase.

No, to the library. :stuck_out_tongue_winking_eye:

In the Strings library is the block

. The other blocks in the library check the flag it sets to decide whether to use case-indpendent (yay!) or case-sensitive (boo!) comparisons. That block doesn't set a Snap! variable; it does this:

var world=this.parentThatIsA(IDE_Morph);
world['stringLibCaseIndependentComparison'] = flag;

so the other blocks need to look up the flag in JS.

I wrote it that way because libraries can't include variables. But now we have the Variables library so I could have


and maybe I should do that.

When you're older, you'll understand. :~P

thanks, it now makes sense.

Yeah, I know, I could do that. But the reason for case conversion is case-independent comparison and that should be in lower case I think. Actually the official right thing is toLowerCase(toUpperCase()) because of the stupid ß which is equivalent to "ss" and becomes "SS" when converted to upper case. Maybe I'll make the Snap! lower case block do that round trip.

P.S. Reading this I see that I didn't really answer the question. Arguably every JS string function should be in this library. But in fact it's just the things I need; the library first appeared when we were doing web page scraping in BJC.

1 Like

But there is also the ẞ (the capital ß)!
By the way, it is is extremely hidden on every keyboard, because it has no real use.

Wait, what? Users may need things you do not need and I am quite sure a large number of users do not know JavaScript, if not most; and may also be struggling to find a Snap! implementation.

Yeah, it's in Unicode, but I guess it isn't used in German. This is the textbook example of why case conversion isn't straightforward.

I know. I suppose we could put every single JS function in a library. But all the string ones can be implemented in Snap!, so other things would come before that, such as the ability to make a phone-sized DOM window and do native-app-like things in it. And maybe even then compile them. And file I/O. And stuff.

Wow, that would be nice.

I see.

Is there any way to make a case sensitive equals block?

Yeah, use
Untitled script pic