Ingo,

Assuming your input line looks like this:

inline: "a1=1, a2=2, a3=3, a4"

Here is a one-line solution to do what you want:

do replace replace/all replace/all inline "," " " "=" ": " "a4" "a4: true"

It works for any ordering of inline, and also if the values are separated by
spaces, commas, tabs or newlines.  The values of A1 through A4 will then be
assigned to words A1 through A4 in REBOL and you can do with them what you
please.  It also doesn't matter what the size of the integer (or decimal)
number that follows each assignment is.  The only requirement is that there
are no spaces between the variable name and the = sign like this "a1 =1".

It can be even shorter if you have the following handy function defined:

multi-replace: func [series [series!] pairs [block!]][
    foreach [a b] pairs [
        replace/all series a b
    ]
]

do multi-replace inline ["," " " "=" ": " "a4" "a4: true"]

If you were asking in order to learn more about PARSE on the other hand,
let me know and I'll show you a way to do it with PARSE (although it will
require a few more lines of script).

Have fun!


On 18-Nov-1999/23:41:09+1:00, [EMAIL PROTECTED] wrote:
>Hi Rebols,
>
>I've got a little parse problem. I try to parse something like
>a1=1, a2=2, a3=3, a4
>where a1 to a3 have to be present, a4 may or may not be there,
>it is unspecified, which is at which position, and they may be
>on subsequent lines, without the commas seperating them.
>
>Any ideas on how to best parse this, to get the values for a1 
>to a3 and the presence of a4, respectively? 
>
>
>thanks in advance
>
>Ingo
>
>--  _     .                                _
>ingo@)|_ /|  _| _  <We ARE all ONE   www._|_o _   _ ._ _  
>www./_|_) |o(_|(/_  We ARE all FREE> ingo@| |(_|o(_)| (_| 
>http://www.2b1.de/Rebol/                     ._|      ._|
>
-- 
                           Bohdan "Bo" Lechnowsky
                           REBOL  Adventure Guide
           REBOL Technologies 707-467-8000 (http://www.rebol.com)
          Download the REBOL Messaging Language for all Platforms

Reply via email to