[REBOL] Re: replace question
From: joel:neely:fedex at: 18-May-2001 22:23
Winston Ng wrote:
> How do you replace several tag markers in a document with
> their corresponding texts from text files?
>
One at a time.
> 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
>
Ask REBOL...
>> ? replace
USAGE:
REPLACE target search replace /all /case
DESCRIPTION:
Replaces the search value with the replace value
within the target series.
REPLACE is a function value.
ARGUMENTS:
target -- Series that is being modified. (Type: series)
search -- Value to be replaced. (Type: any)
replace -- Value to replace with. (Type: any)
REFINEMENTS:
/all -- Replace all occurrences.
/case -- Case-sensitive replacement.
...and notice that the SEARCH and REPLACE arguments are
described as "value" in the singular. To do multiples, just
wrap the replace in a loop that walks through your blocks in
parallel:
mreplace: func [s [series!] rfrom [block!] rto [block!]]
[ while [not any [tail? rfrom tail? rto]]
[ replace/all s rfrom/1
rto/1 rfrom: next
rfrom rto: next
rto
]
s
]
>> test: "this*is*a*$*in*a*string*called*$"
== "this*is*a*$*in*a*string*called*$"
>> mreplace test ["*" "$"] [" " "test"]
== "this is a test in a string called test"
>>
Hope this helps!
-jn-
------------------------------------------------------------
Programming languages: compact, powerful, simple ...
Pick any two!
joel'dot'neely'at'fedex'dot'com