Discuss Scratch
- Discussion Forums
- » Suggestions
- » Sensing block, if string contains string.
- 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 .
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…
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.
though operators is more math than answer. This would just give a true or false response. I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
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.
I guess that is true!though operators is more math than answer. This would just give a true or false response. I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
- DaSpudLord
- Scratcher
1000+ posts
Sensing block, if string contains string.
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-though operators is more math than answer. This would just give a true or false response. I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.
<[] = []>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)
| Primary Target | Fireworks Show! Wheel of Fortune || Block Buster ||||| Shut the Box ||||||||| Surf's Up! |||||
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.
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.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-though operators is more math than answer. This would just give a true or false response. I think this would fit better in the operators category, as the blocks like (letter (n) of (str)) are there too.<[] = []>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.
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.
http://wiki.scratch.mit.edu/wiki/Checking_if_a_String_Contains_a_StringAt the moment, the most effecient way to check if a string contains another string is quite complicated. Workaroundable. It currently only works with one letter not an entire string… Yet.
I would like there to be a block in Sensing, that does this automatically for us .
・Scratcher1002は「ここにランダムな日本語の言葉はたくさんですか?はい」と言いました・
||||Search:
Topics | Users
||Studios | Projects
||
||||Search:
Topics | Users
||Studios | Projects
||
- ChildCritic
- Scratcher
500+ posts
Sensing block, if string contains string.
So you mean like
I don't watch or play soccer. I had no intent for this example.
here is the code for the above blocks.
<string [goalie] contains string [goal]::operators>//returns truesupport.
//or
<string [keeper] contains string [goal]::operators>//returns false
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)
Wings.io!!! Challenge. Contest! How much like me are you? Fall damage Collab Songtrack Crush damage experiment My 100th post! My 250th post! My 500th post!
kumquat poison. Don't try to eat this signature.
- gamebeater187
- Scratcher
1000+ posts
Sensing block, if string contains string.
Duplicate
Workaround:
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.
Yes, That was what I meant . Thanks for demonstrating it. So you mean like<string [goalie] contains string [goal]::operators>//returns truesupport.
//or
<string [keeper] contains string [goal]::operators>//returns false
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]
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.
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.
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.
- 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.
That is actually a good point! I never thought of that, it would make safe-chat ALOT easier to setup. support. this could be used for safe chats
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.
Looping can be fixed with turbo mode, or run without screen refresh. 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.
・Scratcher1002は「ここにランダムな日本語の言葉はたくさんですか?はい」と言いました・
||||Search:
Topics | Users
||Studios | Projects
||
||||Search:
Topics | Users
||Studios | Projects
||
- liam48D
- Scratcher
1000+ posts
Sensing block, if string contains string.
Not really. I can only see this being used in a safe chat as a black list which isn't allowed. support. this could be used for safe chats
202e-202e-202e-202e-202e UNI-CODE~~~~~
- Scratcher1002
- Scratcher
1000+ posts
Sensing block, if string contains string.
Or whitelist.Not really. I can only see this being used in a safe chat as a black list which isn't allowed. support. this could be used for safe chats
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)
・Scratcher1002は「ここにランダムな日本語の言葉はたくさんですか?はい」と言いました・
||||Search:
Topics | Users
||Studios | Projects
||
||||Search:
Topics | Users
||Studios | Projects
||
- ChildCritic
- Scratcher
500+ posts
Sensing block, if string contains string.
In which case:Or whitelist.Not really. I can only see this being used in a safe chat as a black list which isn't allowed. support. this could be used for safe chatsrepeat (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
<[whitelist v] contains (answer)>
Last edited by ChildCritic (Nov. 4, 2015 01:22:47)
Wings.io!!! Challenge. Contest! How much like me are you? Fall damage Collab Songtrack Crush damage experiment My 100th post! My 250th post! My 500th post!
kumquat poison. Don't try to eat this signature.
- Discussion Forums
- » Suggestions
- » Sensing block, if string contains string.