This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-17 20:58:04

MisterDuck
Scratcher
Registered: 2012-05-15
Posts: 8

Splitting/Parsing a value

Maybe a block under "operators" that does the opposite of

 <join [hello] [world]> 
seperated by a character or a few that splits two values apart and gives one, like this:
(split [2&4] [before v] [&])

Offline

 

#2 2012-06-17 21:05:01

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: Splitting/Parsing a value

Another way would be to make a substring function:
SUBSTR("NARUTO",2,3)
would give "ARU", by starting from the 2nd character ("A"), and (while including that) count 3 letters- A, R, and U.
This would be a lot faster than seperating the word into a list.


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#3 2012-06-17 21:34:55

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Splitting/Parsing a value

I think a more understanding way to do this would be to make the

<letter (1) of [1]>
turn into
<letter (1) through (3) of [12345]>
It would have what you want, but in a way that is easier to read.

Offline

 

#4 2012-06-17 21:42:09

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Splitting/Parsing a value

I want a split function that takes a string and a character as input. The result would be a list. The string would be split by the specified character into list entries.

For example, you could easily split a sentence into a word list by specifying a space character.


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#5 2012-06-18 11:43:17

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: Splitting/Parsing a value

TorbyFork234 wrote:

I think a more understanding way to do this would be to make the

<letter (1) of [1]>
turn into
<letter (1) through (3) of [12345]>
It would have what you want, but in a way that is easier to read.

I'm not sure about this, as most other programming languages have the substring do this:
     From the string [NARUTO], start from [2] and get [3] characters.
Also, since Scratch is supposed to help beginner programmers move on to a more complex language, it should be as close to other languages as possible.
At least that's what I think.


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#6 2012-06-18 13:29:17

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Splitting/Parsing a value

BoltBait wrote:

I want a split function that takes a string and a character as input. The result would be a list. The string would be split by the specified character into list entries.

For example, you could easily split a sentence into a word list by specifying a space character.

I agree. I use this a lot in Processing and it's helpful.


Posts: 20000 - Show all posts

Offline

 

#7 2012-06-23 04:56:14

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: Splitting/Parsing a value

There is a way to do so already, but this would be useful.


http://trinary.tk/images/signature_.php

Offline

 

Board footer