Discuss Scratch
- Discussion Forums
- » Suggestions
- » Some more text processing blocks
- BookOwl
-
Scratcher
1000+ posts
Some more text processing blocks
I know that all these blocks are work-aroundable (some more easily than others), but I feel that they would make programming in Scratch much easier.
-
(letters (1) to (3) of [Scratch Cat] ::operators)
If the first number slot was left out, it would default to 1, and if the last number slot was left out, it would default to the length of the string. For example,(letters (9) to () of [Scratch Cat] ::operators)
would return “Cat”
This is probably one of the easiest blocks to work-around, but the convenience (and speed) of having it be a reporter outweigh the cost of adding it. -
(find [nano] in [gobo giag pico nano tera] ::operators)
This block would return the starting position of the first string in the second string.
This block is actually the hardest to work around, and could be used a lot. -
split [gobo giag pico nano tera] by (something v)into [list v] ::list
This block would split the first string by the second string and store the result in a list. The space to type in the second string is also a dropdown that would let you select characters like newline or tab.
This block is the second hardest to work around, and could also be used a lot. -
(replace [dog] in [Scratch dog] with [Cat] ::operators)
This would replace every occurrence of the first string the second string with the third string -
(join everything in [list v] with [, ] ::list)
This would create a string out of a list by sticking the string between every member of the list.
For example, if the list “list” contained [1, 2, 3], than the above call would return “1, 2, 3”
- fivesythe
-
New Scratcher
80 posts
Some more text processing blocks
I think that instead of having Scratch add new blocks whenever we need them, we should have functions so we can make them! By the way how do you make the blocks?
- BookOwl
-
Scratcher
1000+ posts
Some more text processing blocks
I think that instead of having Scratch add new blocks whenever we need them, we should have functions so we can make them! By the way how do you make the blocks?1. That has been suggested before, but I don't think that it is coming anytime soon.
2. See https://scratch.mit.edu/discuss/topic/55586/
- Gaza101
-
Scratcher
500+ posts
Some more text processing blocks
Support; I have no idea why these don't exist yet.
- Ninkancho
-
Scratcher
500+ posts
Some more text processing blocks
More string commands would be nice, I agree.
On that note, what would this return if $1 isn't a substring of $2?
I think this should be named something like (position of () in ()); find sounds more like it would report the number of instances, like Ctrl-F, or just booleanify whether or not the string contains the substring.(find [nano] in [gobo giag pico nano tera] ::operators)
On that note, what would this return if $1 isn't a substring of $2?
- A-no-meep
-
Scratcher
100+ posts
Some more text processing blocks
More string commands would be nice, I agree.Something along the lines of “Not found” / “Not present” / “$1 isn't a substring of $2”I think this should be named something like (position of () in ()); find sounds more like it would report the number of instances, like Ctrl-F, or just booleanify whether or not the string contains the substring.(find [nano] in [gobo giag pico nano tera] ::operators)
On that note, what would this return if $1 isn't a substring of $2?
I support this idea.
- Gaza101
-
Scratcher
500+ posts
Some more text processing blocks
On that note, what would this return if $1 isn't a substring of $2?I would suggest the number -1 or 0 based on Python's implementation of string.find:
string.find(s, sub[, start[, end]])
Return the lowest index in s where the substring sub is found such that sub is wholly contained in s. Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices.
- gdpr533f604550b2f20900645890
-
Scratcher
1000+ posts
Some more text processing blocks
I think that instead of having Scratch add new blocks whenever we need them, we should have functions so we can make them! By the way how do you make the blocks?If one, but not both of the suggestions were to be implemented, I would favor a return block over text manipulation functions. However, I believe both suggestions would be beneficial.
- Sheep_maker
-
Scratcher
1000+ posts
Some more text processing blocks
Would it replace the contents of the list or just add the items on?split [gobo giag pico nano tera] by (something v)into [list v] ::list
- TheLogFather
-
Scratcher
1000+ posts
Some more text processing blocks
I think that (1) is the one that really makes a difference – so many other things then become so much simpler, including both suggestions (2) and (4). (And I've said such a thing numerous times before in these forums, of course.)
I'm not really a fan of adding blocks to Scratch – I think there's pretty much just enough to provide the essential functionality, while leaving out some things (even some really simple things, like “previous costume”!) that you have to then think how to code yourself (which is what Scratch is all about).
The main thing you'd learn from having to write your own “letters M to N” script is how to use a variable as an index counter within a loop. But there are so many other ways you're gonna have to do that anyway (it's such a fundamental concept in so many situations), so I don't really see that having this block added will reduce that learning. Having it, OTOH, does give such a gain (in speed, if nothing else), as well as being so obvious what it's meant to do (esp. since it'd be right under the "letter ( ) of [ ]" block).
What might make it really interesting would be if it actually *reversed* the order of the letters if the first number is higher than the second – I mean, it then does exactly what it says: "letters (8) to (1) of [!haey hO]". :)
I'm not really a fan of adding blocks to Scratch – I think there's pretty much just enough to provide the essential functionality, while leaving out some things (even some really simple things, like “previous costume”!) that you have to then think how to code yourself (which is what Scratch is all about).
The main thing you'd learn from having to write your own “letters M to N” script is how to use a variable as an index counter within a loop. But there are so many other ways you're gonna have to do that anyway (it's such a fundamental concept in so many situations), so I don't really see that having this block added will reduce that learning. Having it, OTOH, does give such a gain (in speed, if nothing else), as well as being so obvious what it's meant to do (esp. since it'd be right under the "letter ( ) of [ ]" block).
What might make it really interesting would be if it actually *reversed* the order of the letters if the first number is higher than the second – I mean, it then does exactly what it says: "letters (8) to (1) of [!haey hO]". :)
Last edited by TheLogFather (March 22, 2016 12:25:18)
- scratchisthebest
-
Scratcher
1000+ posts
Some more text processing blocks
Honestly I think all that Scratch needs is custom reporters HAHAHAHA YEAH LIKE THAT'S GONNA HAPPEN EVER, and an actually usable backpack, and we're golden.
That said, custom blocks will always be slower than a native block, and string operations are sometimes performed “in bulk”? so if you're using a custom block it will be super slow.
That said, custom blocks will always be slower than a native block, and string operations are sometimes performed “in bulk”? so if you're using a custom block it will be super slow.
Last edited by scratchisthebest (March 22, 2016 15:10:58)
- alexphan
-
Scratcher
1000+ posts
Some more text processing blocks
I support for all the operators reporters. They seem very useful for string manipulation.
- Discussion Forums
- » Suggestions
-
» Some more text processing blocks









