Discuss Scratch
- mozarty
-
54 posts
Substring
We need a substring function.
It would be useful for so many things, like decoding and encoding cloud lists.
For those of you who don't know, substring takes a certain part of a string. Look it up, it's a function in Java.

where the string input is, well, the string, and the two numbers are where the section of the string starts and ends.
It would be useful for so many things, like decoding and encoding cloud lists.
For those of you who don't know, substring takes a certain part of a string. Look it up, it's a function in Java.

Last edited by mozarty (March 27, 2014 04:31:16)
- AonymousGuy
-
1000+ posts
Substring
This might be kinda useful, but it does have a somewhat simple workaround:
Well at least I think this works - there might need to be a few tweaks cuz' I haven't tested it.
Well at least I think this works - there might need to be a few tweaks cuz' I haven't tested it.

- A-no-meep
-
100+ posts
Substring
Not a workaround, only gets 1 letter.
Is a workaround, but tough because no return statements in scratch. This might be kinda useful, but it does have a somewhat simple workaround:
Well at least I think this works - there might need to be a few tweaks cuz' I haven't tested it.
I think adding this block would help scratch.
- mozarty
-
54 posts
Substring
That's what I use right now. This might be kinda useful, but it does have a somewhat simple workaround:
Well at least I think this works - there might need to be a few tweaks cuz' I haven't tested it.
But it's really slow. A built-in function would be much faster. And for something like decoding a cloud variable over 100 digits long, it takes a VERY long time.
Last edited by mozarty (March 27, 2014 14:09:29)
- Firedrake969
-
1000+ posts
Substring
You can speed it up by checking “run without screen refresh”That's what I use right now. This might be kinda useful, but it does have a somewhat simple workaround:
Well at least I think this works - there might need to be a few tweaks cuz' I haven't tested it.
But it's really slow. A built-in function would be much faster. And for something like decoding a cloud variable over 100 digits long, it takes a VERY long time.
- Asymptoteles
-
29 posts
Substring
This might be kinda useful, but it does have a somewhat simple workaround:
Two downsides for the “do-it-yourself” version:
- it is still limited (cannot “return” its result as a value)
- one needs to have copies of the “subscript”-block (as well as of an extra variable) for each sprite that needs ranges…
I'd however suggest:
“letters (i1) to (i2) of (string)”
to be more similar to the single-letter “letter (i) of (string)”
I'm aware this thread is about a year old: I felt it was about time to re-wake it up.
- Sonickyle
-
1000+ posts
Substring
On these forums, in most cases if a new block that has been suggested has a workaround, then it's usually rejected.
AonymousGuy has given a workaround that does exactly what you want the new block to do,
AonymousGuy has given a workaround that does exactly what you want the new block to do,
- Le_adrien
-
80 posts
Substring
This might be kinda useful, but it does have a somewhat simple workaround:
Well at least I think this works - there might need to be a few tweaks cuz' I haven't tested it.
No Support.
- stickfire-test
-
100+ posts
Substring
Support. I know it is workaroundable, but Scratch needs more string functions in general considering they are available in most programming languages and aren't that hard to understand.
- matey1234
-
1000+ posts
Substring
my god, once I was doing a script test, and I had to copy like 10Support. I know it is workaroundable, but Scratch needs more string functions in general considering they are available in most programming languages and aren't that hard to understand.
blocks. It was super annoying. So, support for a
block.
- Prinseskat
-
1000+ posts
Substring
How about custom reporters/booleans instead? https://scratch.mit.edu/discuss/topic/20661/Not a workaround, only gets 1 letter.Is a workaround, but tough because no return statements in scratch. This might be kinda useful, but it does have a somewhat simple workaround:
Well at least I think this works - there might need to be a few tweaks cuz' I haven't tested it.
I think adding this block would help scratch.
- Zro716
-
1000+ posts
Substring
Support. The substring function is one of the most essential and most useful String manipulation methods of any language. Even though I've mastered the workaround a dozen times over, I still get annoyed by the lack of it. My only concern for it now is what wording to use: letters (a) to (b) of [string] or substring (a) thru (b) of [string] and so on. I'd go with the “letters” version since that associates well with the current “letter” block.
- NDSDNS
-
1000+ posts
Substring
This is implemented in Panther, so useful. Support, although I have to use the substring in if statements so workarounds won't work too well. We need a substring function.where the string input is, well, the string, and the two numbers are where the section of the string starts and ends.
It would be useful for so many things, like decoding and encoding cloud lists.
For those of you who don't know, substring takes a certain part of a string. Look it up, it's a function in Java.
- liam48D
-
1000+ posts
Substring
Support as per above but probably with the wording (letters (a) through (b)). No thru! Support. The substring function is one of the most essential and most useful String manipulation methods of any language. Even though I've mastered the workaround a dozen times over, I still get annoyed by the lack of it. My only concern for it now is what wording to use: letters (a) to (b) of [string] or substring (a) thru (b) of [string] and so on. I'd go with the “letters” version since that associates well with the current “letter” block.
- Phosphor
-
71 posts
Substring
I'm supporting this version:
In addition, leaving the first number parameter empty lets you take letters from the start of the string, and leaving the second number parameter empty lets you take letters from the end. (It's similar to Python's slice notation, but not the same.)
Edit Jan. 7, 2016
The second example is different from this usage, which takes characters from an index all the way to the end of the string. (Thanks for pointing this out, Asymptoteles!)
In addition, leaving the first number parameter empty lets you take letters from the start of the string, and leaving the second number parameter empty lets you take letters from the end. (It's similar to Python's slice notation, but not the same.)
Edit Jan. 7, 2016
The second example is different from this usage, which takes characters from an index all the way to the end of the string. (Thanks for pointing this out, Asymptoteles!)
Last edited by Phosphor (Jan. 7, 2016 09:30:53)
- Gustavo6046
-
100+ posts
Substring
Ahhh, the (not-so-)good days I used Python before learning C++! Lol I'm supporting this version:
In addition, leaving the first number parameter empty defaults to the start of the string, and leaving the second number parameter empty defaults to the end of the string. (It's similar to Python's slice notation.)
By the way, support.
Last edited by Gustavo6046 (Jan. 1, 2016 22:30:15)
- Asymptoteles
-
29 posts
Substring
Ahhh, the (not-so-)good days I used Python before learning C++! Lol I'm supporting this version:
In addition, leaving the first number parameter empty defaults to the start of the string, and leaving the second number parameter empty defaults to the end of the string. (It's similar to Python's slice notation.)
By the way, support.
I'm unsure about the last example. Why does it start with 4th letter from right side, rather than left side?
rather:
Last edited by Asymptoteles (Jan. 7, 2016 02:12:24)
- Phosphor
-
71 posts
Substring
Ahhh, the (not-so-)good days I used Python before learning C++! Lol I'm supporting this version:
In addition, leaving the first number parameter empty defaults to the start of the string, and leaving the second number parameter empty defaults to the end of the string. (It's similar to Python's slice notation.)
By the way, support.
I'm unsure about the last example. Why does it start with 4th letter from right side, rather than left side?
rather:
Oh, good point! ^^; I'll change the original post in a second, so it says something like “taking letters from the start/end of the string”. That should be much better.
Small ramble: The original slice notation used negative indices to indicate taking letters from the end of a string. Since we can't use them in Scratch, that's the best implementation I can think of… but someone else might have a better idea!