Reputation: 38228
I'm trying to understand parse from the ground up so don't tell me to use split in this case.
sentence: "This is a sentence"
parse sentence [
any [
[any space] copy text [to space | to end] skip
(print text)
]
]
Why do I not get the last word in the sentence, and only:
This
is
a
Did the [to end]
not work?
Upvotes: 3
Views: 106
Reputation: 6436
An alternative solution without to and end
sentence: "This is a sentence"
space: charset " "
chars: complement space
parse sentence [
any [
any space
copy text some chars
(print text)
]
]
In Rebol2 you have to use parse/all, if you deal with strings, but the most simple solution in Rebol2 for splitting is
>> parse sentence none
== ["This" "is" "a" "sentence"]
Upvotes: 1
Reputation: 1301
to end
did work, but then you have skip
there and you're already at the end, so skip
fails. See this:
>> parse sentence [any [[any space] copy text [to space | to end ] (print text) skip]]
This
is
a
sentence
Upvotes: 4