If you're using nsd8x (and not nsd76) you can get your desired result by
using [string map] instead of [regsub]:
proc insert_macro { thestring key macro} {
return [string map [list $key $macro] $thestring]
}
See:
http://aolserver.com/docs/devel/tcl/tcl-language/tcl8.x/TclCmd/string.htm#M34
Michael
On Fri, 22 Feb 2002, Patrick Spence wrote:
> This is a stripped down version of a template system I am working on. The
> problem I am having is that by specification (annoyingly :) ) regsub has
> this caveat:
>
> "If subSpec contains a ``&'' or ``\0'', then it is replaced in the
> substitution with the portion of string that matched exp. If subSpec
> contains a ``\n'', where n is a digit between 1 and 9, then it is replaced
> in the substitution with the portion of string that matched the n-th
> parenthesized subexpression of exp. Additional backslashes may be used in
> subSpec to prevent special interpretation of ``&'' or ``\0'' or ``\n'' or
> backslash. The use of backslashes in subSpec tends to interact badly with
> the Tcl parser's use of backslashes, so it's generally safest to enclose
> subSpec in braces if it includes backslashes."
>
> My problem is I cannot insert the \ before the & and then wrap with braces..
> I am pulling the string to convert from a database and piping it through my
> macro routine and I have not been able to figure out how to get it to work
> right.
>
> The result of the following procedures gives me:
>
> (this is a test) Blah Blah --CONTENT-- --CONTENT-- Blah Blah (this is a
> test)
>
> when I really want :
>
> (this is a test) Blah Blah & & Blah Blah (this is a test)
>
> from it since I am using it for html code and that html does contain the
> ampersand in places where it needs to stay.
>
> I am at a loss here and if anyone has suggestions on some way to handle this
> without a lot of headaches I would appreciate it.
>
> Thanks :)
>
>
>
> proc insert_macro { thestring key macro} {
> regsub -all -- $key $thestring $macro thestring;
> return "$thestring"
> }
>
> proc testmacro { } {
> set html [insert_macro "(this is a test) --CONTENT-- (this is a test)"
> "--CONTENT--" "Blah Blah & & Blah Blah"]
> puts $html
> }
>
> testmacro
>
>
> --
> Patrick Spence, MIS
> Mayor Pharmaceutical Labs/Regency Medical Research, Ltd.
> 2401 South 24th Street, Phoenix, AZ 85034
> [EMAIL PROTECTED] - http://www.vitamist.com
>