Discuss Scratch

BowWhalley
Scratcher
100+ posts

Sensing block, if string contains string.

At the moment, the most effecient way to check if a string contains another string is quite complicated. http://wiki.scratch.mit.edu/wiki/Checking_if_a_String_Contains_a_String

I would like there to be a block in Sensing, that does this automatically for us .


Check out my new WIP MAP. I need people to join - 9th March 2018
Please check out my new game, AppleCatch! - 8th March 2018
Profile picture made by @HelloUnicorns2

Leadrien2366
Scratcher
100+ posts

Sensing block, if string contains string.

Support.
Dang it, 120 second rules…
ChocolatePi
Scratcher
1000+ posts

Sensing block, if string contains string.

I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
BowWhalley
Scratcher
100+ posts

Sensing block, if string contains string.

ChocolatePi wrote:

I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
though operators is more math than answer. This would just give a true or false response.


Check out my new WIP MAP. I need people to join - 9th March 2018
Please check out my new game, AppleCatch! - 8th March 2018
Profile picture made by @HelloUnicorns2

ChocolatePi
Scratcher
1000+ posts

Sensing block, if string contains string.

BowWhalley wrote:

ChocolatePi wrote:

I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
though operators is more math than answer. This would just give a true or false response.
I guess that is true!
DaSpudLord
Scratcher
1000+ posts

Sensing block, if string contains string.

BowWhalley wrote:

ChocolatePi wrote:

I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
though operators is more math than answer. This would just give a true or false response.
Operators is for handling strings, too. Sensing is for detecting stuff about what is going on in the screen (like the touching color block), detecting other sprites (distance to sprite), and getting data from the outside world (mouse position, key pressed, webcam, date and time, etc). Operators is for handling, transforming, and analyzing any type of data, including strings. One example of this is-
<[] = []>
This is used for sensing both numbers and strings (as indicated by the rectangular textboxes). So I feel like if this block was implemented, it would go in operators.

Anyway, semi-support because the workaround is a good one to know, as the knowledge gained from knowing it is useful for creating lots of other blocks.

Last edited by DaSpudLord (Oct. 30, 2015 18:56:22)



U^ェ^U::motion//This is Blocky. He lives in my signature. He is a trained attack block. He protects my siggy from kumquats.
BowWhalley
Scratcher
100+ posts

Sensing block, if string contains string.

DaSpudLord wrote:

BowWhalley wrote:

ChocolatePi wrote:

I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
though operators is more math than answer. This would just give a true or false response.
Operators is for handling strings, too. Sensing is for detecting stuff about what is going on in the screen (like the touching color block), detecting other sprites (distance to sprite), and getting data from the outside world (mouse position, key pressed, webcam, date and time, etc). Operators is for handling, transforming, and analyzing any type of data, including strings. One example of this is-
<[] = []>
This is used for sensing both numbers and strings (as indicated by the rectangular textboxes). So I feel like if this block was implemented, it would go in operators.

Anyway, semi-support because the workaround is a good one to know, as the knowledge gained from knowing it is useful for creating lots of other blocks.
You have a good point there, though it is none of our choices for where it goes, it is the scratch teams if they choose to implement this.


Check out my new WIP MAP. I need people to join - 9th March 2018
Please check out my new game, AppleCatch! - 8th March 2018
Profile picture made by @HelloUnicorns2

Scratcher1002
Scratcher
1000+ posts

Sensing block, if string contains string.

BowWhalley wrote:

At the moment, the most effecient way to check if a string contains another string is quite complicated. http://wiki.scratch.mit.edu/wiki/Checking_if_a_String_Contains_a_String

I would like there to be a block in Sensing, that does this automatically for us .
Workaroundable. It currently only works with one letter not an entire string… Yet.
ChildCritic
Scratcher
500+ posts

Sensing block, if string contains string.

So you mean like
<string [goalie] contains string [goal]::operators>//returns true
//or
<string [keeper] contains string [goal]::operators>//returns false
support.
I don't watch or play soccer. I had no intent for this example.

here is the code for the above blocks.
[scratchblocks]
<string [goalie] contains string [goal]::operators>
<string [keeper] contains string [goal]::operators>
[/scratchblocks]

Last edited by ChildCritic (Oct. 30, 2015 22:08:37)

gamebeater187
Scratcher
1000+ posts

Sensing block, if string contains string.

Duplicate
Workaround:
define [string] contains [substring]?
set [counter v] to [1]
set [counter2 v] to [1]
set [parse v] to []
repeat until <<(parse) = (substring)> or <(counter) > (length of (string))>>
if <(letter (counter) of (string)) = (letter (counter 2) of (substring))>
set [parse v] to (join (parse)(letter (counter) of (string)))
change [counter 2 v] by (1)
else
set [parse v] to []
set [counter 2 v] to [1]
end
change [counter v] by (1)
end
if <(parse) = (substring)>
set [contains? v] to [true]
else
set [contains? v] to [false]
end

Last edited by gamebeater187 (Oct. 30, 2015 23:26:55)


My 1000th post!
I haven't changed my logo since my 96th post on 2014. Now at 1000 posts, I changed my logo!
BowWhalley
Scratcher
100+ posts

Sensing block, if string contains string.

ChildCritic wrote:

So you mean like
<string [goalie] contains string [goal]::operators>//returns true
//or
<string [keeper] contains string [goal]::operators>//returns false
support.
I don't watch or play soccer. I had no intent for this example.

here is the code for the above blocks.
[scratchblocks]
<string [goalie] contains string [goal]::operators>
<string [keeper] contains string [goal]::operators>
[/scratchblocks]
Yes, That was what I meant . Thanks for demonstrating it.


Check out my new WIP MAP. I need people to join - 9th March 2018
Please check out my new game, AppleCatch! - 8th March 2018
Profile picture made by @HelloUnicorns2

BowWhalley
Scratcher
100+ posts

Sensing block, if string contains string.

gamebeater187 wrote:

Duplicate
Workaround:
define [string] contains [substring]?
set [counter v] to [1]
set [counter2 v] to [1]
set [parse v] to []
repeat until <<(parse) = (substring)> or <(counter) > (length of (string))>>
if <(letter (counter) of (string)) = (letter (counter 2) of (substring))>
set [parse v] to (join (parse)(letter (counter) of (string)))
change [counter 2 v] by (1)
else
set [parse v] to []
set [counter 2 v] to [1]
end
change [counter v] by (1)
end
if <(parse) = (substring)>
set [contains? v] to [true]
else
set [contains? v] to [false]
end


Yes, though there is a work, arround. It is more complicated than a simple
<string [goalie] contains string [goal]::operators>  //true
//or
<string [keeper] contains string [goal]::operators> //false

Last edited by BowWhalley (Oct. 31, 2015 04:07:55)



Check out my new WIP MAP. I need people to join - 9th March 2018
Please check out my new game, AppleCatch! - 8th March 2018
Profile picture made by @HelloUnicorns2

stickfiregames
Scratcher
1000+ posts

Sensing block, if string contains string.

Support.

The reason I don't think the workaround is a good excuse for not adding it is because it uses a lot of looping, which is slower than having a single block especially when you are working with long strings.










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
DatOneLefty
Scratcher
1000+ posts

Sensing block, if string contains string.

support. this could be used for safe chats


Scratch data available at ScratchDB (Status)

Posts: bf97b44a7fbd33db070f6ade2b7dc549 (btw i use arch)
BowWhalley
Scratcher
100+ posts

Sensing block, if string contains string.

DatOneLefty wrote:

support. this could be used for safe chats
That is actually a good point! I never thought of that, it would make safe-chat ALOT easier to setup.


Check out my new WIP MAP. I need people to join - 9th March 2018
Please check out my new game, AppleCatch! - 8th March 2018
Profile picture made by @HelloUnicorns2

Scratcher1002
Scratcher
1000+ posts

Sensing block, if string contains string.

stickfiregames wrote:

Support.

The reason I don't think the workaround is a good excuse for not adding it is because it uses a lot of looping, which is slower than having a single block especially when you are working with long strings.
Looping can be fixed with turbo mode, or run without screen refresh.
Leadrien2366
Scratcher
100+ posts

Sensing block, if string contains string.

Support.
liam48D
Scratcher
1000+ posts

Sensing block, if string contains string.

DatOneLefty wrote:

support. this could be used for safe chats
Not really. I can only see this being used in a safe chat as a black list which isn't allowed.

202e-202e-202e-202e-202e UNI-CODE~~~~~
Scratcher1002
Scratcher
1000+ posts

Sensing block, if string contains string.

liam48D wrote:

DatOneLefty wrote:

support. this could be used for safe chats
Not really. I can only see this being used in a safe chat as a black list which isn't allowed.
Or whitelist.
repeat (length of [whitelist v])
if <string (answer) contains (item (a) of [whitelist v])? :: operators
add (answer) to [Cloud List v]
end
change [a v] by (1)
end

Last edited by Scratcher1002 (Nov. 3, 2015 23:43:43)

ChildCritic
Scratcher
500+ posts

Sensing block, if string contains string.

Scratcher1002 wrote:

liam48D wrote:

DatOneLefty wrote:

support. this could be used for safe chats
Not really. I can only see this being used in a safe chat as a black list which isn't allowed.
Or whitelist.
repeat (length of [whitelist v])
if <string (answer) contains (item (a) of [whitelist v])? :: operators
add (answer) to [Cloud List v]
end
change [a v] by (1)
end
In which case:
<[whitelist v] contains (answer)>

Last edited by ChildCritic (Nov. 4, 2015 01:22:47)

Powered by DjangoBB