rnso
rnso

Reputation: 24535

Converting long string to individual words in Red/Rebol

How can a string with a sentence be converted to a series of words, e.g. convert following string to:

str: "This is a sentence with some words"

to a series of:

["This" "is" "a" "sentence" "with" "some" "words"]

There seems to be a split function in Rebol3 but no such function in Rebol2.

I tried following code with parse but it does not work:

str: "This is a sentence with some words"
strlist: []
parse str [
    some got: " " (append strlist got) ]

Error is:

** Script Error: Invalid argument: got

How can this be achieved (a method with parse will be preferable)?

Upvotes: 1

Views: 138

Answers (2)

kealist
kealist

Reputation: 1679

In Rebol 2, this would be:

str: "This is a sentence with some words"
parse str none

resulting in:

["This" "is" "a" "sentence" "with" "some" "words"]

As mentioned in the comments on your post, the documentation. Parse has two modes, one of which is string splitting.

Rebol 3, split will work.

Upvotes: 2

Shultc
Shultc

Reputation: 214

It will be

split str " "

Where split is function. First argument is your string, and second — delimiter.

Upvotes: 2

Related Questions