1

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)?

5
  • 1
    In Rebol 2, you split using PARSE: parse "foo bar baz" " " Commented Sep 27, 2017 at 19:29
  • How does it work? Commented Sep 27, 2017 at 19:55
  • 1
    convenience feature, not recommended or available in rebol3 or red Commented Sep 27, 2017 at 21:17
  • Yep, just noted for historical reasons. Use SPLIT instead. Commented Sep 27, 2017 at 21:18
  • See documentation. Commented Sep 27, 2017 at 21:19

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You can also add how it can be done in Red language.
2

It will be

split str " " 

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

2 Comments

This does not work in Rebol 2.7.8. ** Script Error: split has no value
Can't find documentation for Rebol 2. In Rebol 3 should work: rebol.com/r3/docs/functions/split.html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.