Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

replace question

 [1/5] from: winsng:optusnet:au at: 19-May-2001 10:05


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

 [2/5] from: john:schuhr at: 18-May-2001 21:24


Changing the assignment of 'items to: items: reduce [replace1 replace2] may get it to do what you're after. --John At 10:05 AM 5/19/2001 +1000, you wrote:

 [3/5] 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
<<quoted lines omitted: 4>>
> 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

 [4/5] from: winsng::optusnet::com::au at: 19-May-2001 12:44


I changed to item: reduce [replace1 replace2] as you said and it still did not work.

 [5/5] 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
<<quoted lines omitted: 7>>
> 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

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted