[REBOL] Re: replace question
From: gjones05:mail:orion at: 19-May-2001 10:00
From: "Winston Ng"
> How do you replace several tag markers in a
> document with their corresponding texts from
> text files? I did the following and it did not
> work:
>
> The idea is to replace markers with different texts
>
> replace1: read %replace1.r ;simple texts
> replace2: read %replace2.r ;simple texts
> body: read %body.r ;contains the markers
> markers: ["<--tag1-->" <--tag2-->"]
> items: [replace1 replace2]
>
> replace body markers items ;this did not work, no error
Hi, Winston,
Let me say right up front that I am not sure that I really understand
what kind of information is in what file. I cooked up the following as
on method for doing tag-like replacements. I'm almost certain that
there is a more efficient way than what I've shown, but I'm out of time
for now. Also, I suspect that you may be envisioning something else
entirely. Without further ado:
;;;;;;;;;;
replace1: ["<--tag1-->" "John Doe"]
replace2: ["<--tag2-->" "123 Main Street"]
all-markers: copy []
append all-markers replace1
append all-markers replace2
body: {
<--tag1-->
<--tag2-->
Dear <--tag1-->;
We are writing you to find out
whether you still live at <--tag2-->.
If you do not live there, then do not
respond to this letter that has been
sent to that address. ;-)
Sincerely,
Non Logic Al
}
a: parse/all body " .^/"
foreach b a [
if s: select all-markers b [
replace/all body b s
]
]
print body
;;;;;;;;;;
Hope this is somewhat helpful (see my prior post to Brett ;-)
--Scott Jones