Discuss Scratch

Bricky5
Scratcher
7 posts

How do I separate a string into words?

define Separate (input) into words
just give up you're never doing this alone :: grey
This is why I came here.
Separate [stuff] into characters :: custom
works fine, but i cant figure out
Separate [a sentence or something] into words :: custom
i would like some help.
Scratcher1002
Scratcher
1000+ posts

How do I separate a string into words?

Here's the script:
define separate (input) into words
set [str v] to [] // blankspace
set [a v] to [1]
repeat until <(letter (a) of (input)) = []> // blankspace
set [str v] to (join (str) (letter (a) of (input)))
if <(letter (a) of (input)) = [ ]> then // space
add (str) to [list v]
set [str v] to [] // blankspace
end
change [a v] by (1)
end
add (str) to [list v]
TheUltimatum
Scratcher
1000+ posts

How do I separate a string into words?

Use this:

define split [str] with [c]::more
set [i v] to [0]
set [j v] to [] //This is set to a blank.
delete (all v) of [words v]
repeat (length of (str))
change [i v] by [1]
if <(letter (i) of (str)) = [ ]> then //This is set to a space.
add (j) to [words v]
set [j v] to [] //Set this to a blank again.
else
set [j v] to (join (j) (letter (i) of (str)))
end
end
if <not <(j) = []>> then
add (j) to [words v]
set [j v] to []
end

Aww stink ninja'd.

Last edited by TheUltimatum (July 20, 2017 17:04:55)

Bricky5
Scratcher
7 posts

How do I separate a string into words?

thanks
Explode [confetti v] [everywhere v] :: custom
hi_me_loaf79
Scratcher
6 posts

How do I separate a string into words?

How could you split a string up between keywords like a space bar or a / like in python with the .split() command. Could it look something like this?

set [input] to [Hello World!]

define split string (string) up between keyword (keyword)
magic, or whatever you come up with (input var)
set [output] to [For Example: A list contaning ("Hello" "World!")]

Please Help
scratchcode1_2_3
Scratcher
1000+ posts

How do I separate a string into words?

hi_me_loaf79 wrote:

(#5)
How could you split a string up between keywords like a space bar or a / like in python with the .split() command. Could it look something like this?

set [input] to [Hello World!]

define split string (string) up between keyword (keyword)
magic, or whatever you come up with (input var)
set [output] to [For Example: A list contaning ("Hello" "World!")]

Please Help

This topic is from 2017, 6 years ago. Please don't necropost. If you still need help with your problem, you should create a new topic by clicking the “New topic” button in the corner of the page shown here:






Have a nice day!



NotK3ndricAlt
Scratcher
1000+ posts

How do I separate a string into words?

hi_me_loaf79 wrote:

How could you split a string up between keywords like a space bar or a / like in python with the .split() command. Could it look something like this?

set [input] to [Hello World!]

define split string (string) up between keyword (keyword)
magic, or whatever you come up with (input var)
set [output] to [For Example: A list contaning ("Hello" "World!")]

Please Help
Please dont necropost. This was from 2017.

Powered by DjangoBB