Hi Allessandro

Yes, there are at least 2 caveats to the approach of converting the string
to a block of  REBOL words with

>> string: "This is a string with some words"
== "This is a string with some words"
>> b: to-block "This is a string with some words"
== [This is a string with some words]
>> type? first b
== word!

The first caveat is that not everything we may want as "words" is a valid
REBOL word.

>> to-block "This is a string |\funny"
** Syntax Error: Invalid word -- |\funny.
** Where: (line 1) This is a string |\funny

So the conversion fails.

The second caveat is that the REBOL dictionary only holds 2558 words.

>> repeat j 3000 [append b to-word join 'word j]
** Internal Error: No more global variable space.
** Where: to word! :value
>> length? first rebol/words
== 2558

CAUTION: There is no way to remove words from the dictionary, the GC does
not touch them.  In order to create a new word after this experiment, you
will have to start a new REBOL session.

So if there are many unique "words" in the string, you will permanently tie
up space in the REBOL dictionary.

Galt's solution:

string: "This is a string with some words"
blk: parse/all string " "
print first back find blk "with"

is much better, because it converts the string to a block of string! values
rather than a block of REBOL words.

If you want to just parse on any whitespace (including linefeed, etc), you
can use

>> parse string none
== ["This" "is" "a" "string" "with" "some" "words"]

which in this case gives the same result as parse/all string " "

-Larry

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 11, 2000 3:00 PM
Subject: [REBOL] Re: Finding the previous value in a string Re:


> >- Open Your Mind -<
>
>
>
> Quoting from [EMAIL PROTECTED]'s message (11-Aug-00 22:47:59).
>
> s> ; How about this:
> s>
> s> string: "This is a string with some words"
> s> select head reverse to-block string 'with
>
> ... or maybe ...
>     first back find to-block string 'with
>
> s> ; Or...
> s>
> s> to-string select head reverse to-block string 'with
> s>
> s> ; ... if you need it converted back into a string.
>
> ... or maybe ...
>     to-string first back find to-block string 'with
>
>
> There is some caveat with my approach, but I'm falling down due to severe
lack of sleep and I can't remember it, so goodnight. :-)
>
>
>
>
> Alessandro Pini ([EMAIL PROTECTED])
>
> "Have you been getting enough sleep?" "More or less. Mostly less."
(E.M.H.P. & Janeway)
>

Reply via email to