Discuss Scratch

MegaApuTurkUltra
Scratcher
1000+ posts

If a string contains something.

Langdon35 wrote:

So this is like dissecting a sentence into letters, and then checking if it contains a certain character, and if it does, it returns true?
I feel that you could easily make this with custom blocks: NO SUPPORT
Ok, maybe a little.
Not just letters, but words too. I have written a lot of boilerplate ApuC including some for this:
def substrMatches(haystack, needle, startIndex){ // boilerplate sub-function
// I built some other string functions off of this as well such as replace and split
for(j=1;j<=lengthOf(needle);j++){
if(!(letterAt(j+startIndex - 1, haystack) == letterAt(j, needle))){
return 0;
}
}
return 1;
}
def strContains(haystack, needle){ // actual function
for(i=1;i<=lengthOf(haystack)-lengthOf(needle);i++){
x = substrMatches(haystack, needle, i); // upper function needed here
if(x == 1){ return 1; }
}
return 0;
}
but as you can see it's very complicated and obviously very slow. It would be better if Scratch had this built in.
RPFluffy
Scratcher
1000+ posts

If a string contains something.

MegaApuTurkUltra wrote:

Support! Scratch needs more string functions in general because implementing them yourself (like I had to do in one of my projects) is annoying!
How about
(position of [substring] in [epic substring plus some more stuff]::operators) // returns -1 for not found, 1 to length(2nd param) if found
(slice [epic string] at (2) to (3)::operators) // same as substring() in JS/Java/PHP/etc
<is uppercase [l]?::operators> // true if the letter is uppercase, otherwise false
([epic string] as all [uppercase/lowercase v]::operators)
// and how about byte/char conversions for hash functions
(number (67) as character::operators)
(letter [s] as number::operators)
I could go on and on…

I agree with ALL of these
TheHockeyist
Scratcher
1000+ posts

If a string contains something.

Major bump.
TimothyLawyer
Scratcher
1000+ posts

If a string contains something.

No support for a dedicated block for this.

Langdon35 wrote:

I feel that you could easily make this with custom blocks
Yes, this would be an ideal operation for a custom operator or function.
theonlygusti
Scratcher
1000+ posts

If a string contains something.

Support.
Mega_Guy
Scratcher
18 posts

If a string contains something.

SUPPORT
theonlygusti
Scratcher
1000+ posts

If a string contains something.

TimothyLawyer wrote:

No support for a dedicated block for this.

Langdon35 wrote:

I feel that you could easily make this with custom blocks
Yes, this would be an ideal operation for a custom operator or function.
You mean custom reporter.
TimothyLawyer
Scratcher
1000+ posts

If a string contains something.

theonlygusti wrote:

You mean custom reporter.
No, I mean a custom operator or function. We already have a custom reporter – variables.
theonlygusti
Scratcher
1000+ posts

If a string contains something.

TimothyLawyer wrote:

theonlygusti wrote:

You mean custom reporter.
No, I mean a custom operator or function. We already have a custom reporter – variables.
An operator is not the same as a function.

Variables are not custom reporters, yes, they report a value, but in Scratch terms, custom reporter refers to a non-void function which can be defined by the user, not a variable.
seanbobe
Scratcher
500+ posts

If a string contains something.

pepper. use variables
theonlygusti
Scratcher
1000+ posts

If a string contains something.

seanbobe wrote:

pepper. use variables
Wait, does pepper mean no support?
coolgem923
Scratcher
100+ posts

If a string contains something.

This is an old topic, but still, this should be made! Support!
MrSherlockHolmes
Scratcher
500+ posts

If a string contains something.

TheHockeyist wrote:

Bump.
Support, but you could just use http://scratch.mit.edu/discuss/topic/74544/
TheHockeyist
Scratcher
1000+ posts

If a string contains something.

(This topic is still alive by the way. I just didn't want to go through my zillions of old posts to find this one specifically and bump it.)
Doodle-cats
Scratcher
500+ posts

If a string contains something.

Support!
PaganoLeo10
Scratcher
100+ posts

If a string contains something.

Support!
Critic2100
Scratcher
1000+ posts

If a string contains something.

Support!
coolgem923
Scratcher
100+ posts

If a string contains something.

Support!
ealgase
Scratcher
100+ posts

If a string contains something.

MegaApuTurkUltra wrote:

Support! Scratch needs more string functions in general because implementing them yourself (like I had to do in one of my projects) is annoying!
How about
(position of [substring] in [epic substring plus some more stuff]::operators) // returns -1 for not found, 1 to length(2nd param) if found
(slice [epic string] at (2) to (3)::operators) // same as substring() in JS/Java/PHP/etc
<is uppercase [l]?::operators> // true if the letter is uppercase, otherwise false
([epic string] as all [uppercase/lowercase v]::operators)
// and how about byte/char conversions for hash functions
(number (67) as character::operators)
(letter [s] as number::operators)
I could go on and on…
Support with all of these.
Also:
(letters (1) to (3) of [hello]::operators)
MegaApuTurkUltra
Scratcher
1000+ posts

If a string contains something.

ealgase wrote:

Also:
(letters (1) to (3) of [hello]::operators)
(slice [epic string] at (2) to (3)::operators) // same as substring() in JS/Java/PHP/etc
“letters of” might be a better name

Last edited by MegaApuTurkUltra (Feb. 14, 2015 16:56:10)

Powered by DjangoBB