Discuss Scratch

TheForceStudio
Scratcher
100+ posts

How to create fast split function

Hello there! I have a question: how to create fast split function?

Okay, firstly - my split function:


Is there a way to somehow improve this function, make it more compact?
The point is that the function splits the string into list items, and that there is a certain character which separates them
TheForceStudio
Scratcher
100+ posts

How to create fast split function

(i know that i can use “run without screen reflesh”, im already use it, but i search more compact function)
Oumuamua
Scratcher
1000+ posts

How to create fast split function

TheForceStudio wrote:

Hello there! I have a question: how to create fast split function?

Okay, firstly - my split function:


Is there a way to somehow improve this function, make it more compact?
The point is that the function splits the string into list items, and that there is a certain character which separates them

Hi, only a bit, but yes



Greetings.
StrangeMagic32
Scratcher
1000+ posts

How to create fast split function

Oumuamua wrote:

Hi, only a bit, but yes
-snip-
Greetings.
That cuts out the first half of the text

TheForceStudio wrote:

Is there a way to somehow improve this function, make it more compact?
Depends, do you want it more compact height wise, or total block count?

Last edited by StrangeMagic32 (April 7, 2020 23:47:35)

Oumuamua
Scratcher
1000+ posts

How to create fast split function

StrangeMagic32 wrote:

That cuts out the first half of the text

Yep. i tested it, but there was a space as first letter

Greetings.
joshpinto6
Scratcher
45 posts

How to create fast split function

EDIT: Just put this in a custom block set to ‘run without screen refresh’.
Yes, there is a way to do this you need four variables:
(Current)
(i)
(ValuetoSplit)
(SplitSymbol)

And one list:

(Output :: list)


when green flag clicked
set [i v] to [1]
repeat until < (i) > (length of (ValuetoSplit))>
set [Current v] to []
repeat until <<(letter (i) of (ValuetoSplit)) = (SplitSymbol)> or <(i) > (length of (ValuetoSplit))>

set [Current v] to (join (Current) (letter (i) of (ValuetoSplit))
change [i v] by [1]
end
add (Current) to [Output v]
change [i v] by [1]
end

This script will go through the “ValuetoSplit” And seperate it into parts which it will then add to the “Output” list. Hope this works!
Happy Scratching!

Last edited by joshpinto6 (April 8, 2020 12:33:53)

TheForceStudio
Scratcher
100+ posts

How to create fast split function

StrangeMagic32 wrote:

Depends, do you want it more compact height wise, or total block count?
I want it to be smaller in height, I think it would be prettier

Oumuamua wrote:

I think my code is better, because zero#k will be equal to the length of the text, and not 1 more. For me it is much more correct!

joshpinto6 wrote:

EDIT: Just put this in a custom block set to ‘run without screen refresh’.
Yes, there is a way to do this you need four variables:
(Current)
(i)
(ValuetoSplit)
(SplitSymbol)

And one list:

* code *

This script will go through the “ValuetoSplit” And seperate it into parts which it will then add to the “Output” list. Hope this works!
Happy Scratching!
Thank you, but I think the code has not become more compact, but rather - it has more variables (now there are 2 instead of 1), and it is even higher in height. But thanks for the way!
StrangeMagic32
Scratcher
1000+ posts

How to create fast split function

This is more compact (height wise), but it does have it's own problems once you try doing different lengths of strings
https://scratch.mit.edu/projects/383629453/

Last edited by StrangeMagic32 (April 8, 2020 14:35:44)

TheForceStudio
Scratcher
100+ posts

How to create fast split function

StrangeMagic32 wrote:

This is more compact (height wise), but it does have it's own problems once you try doing different lengths of strings
https://scratch.mit.edu/projects/383629453/
I fixed this error
define split (text) by (symbol)
set [# v] to (length of (text))

Thank you all for your help, I close the topic (in a few hours, maybe someone will offer something else)!
I realized that this is the most optimal code.

Powered by DjangoBB