I have been trying to find a way to substitute a variable within
quotes within braces..
eg : i need to pass following string as an argument to a procedure.
{<ab:max><ab:mid="xyz:abc...@pqrs.com"/></wyty:ert>}
I want to assign ' xyz:abc...@pqrs.com' to a variable say abhi.
so my string should look like :
{<ab:max><ab:mid="$abhi"/></wyty:ert>} .
Can anyone please help me to solve this trick in TCl..?
Thanks in advance ...
Abhilasha
Does this answer your question?
% set x xyz:abc...@pqrs.com
xyz:abc...@pqrs.com
% set y {<ab:max><ab:mid="$x"/></wyty:ert>}
<ab:max><ab:mid="$x"/></wyty:ert>
% set z [subst -nocommands $y]
<ab:max><ab:mid="xyz:abc...@pqrs.com"/></wyty:ert>
If not, maybe the following does:
% set y {{<ab:max><ab:mid="$x"/></wyty:ert>}}
{<ab:max><ab:mid="$x"/></wyty:ert>}
% set z [subst -nocommands $y]
Someone else has already mentioned subst; does simply changing the
quoting mechanism not work for you?
set string "<ab:max><ab:mid=\"$abhi\"/></wyty:ert>"
This can, of course, cause you to generate invalid xml if $abhi contains
xml-special characters (such as unbalanced <'s, "'s, etc) but
presumably you are taking care of that.
--
Bryan Oakley
http://www.tclscripting.com
Build it in pieces:
set abhi xyz:abc...@pqrs.com
set result {}
append result {<ab:max><ab:mid="} $abhi {"/></wyty:ert>}
=> <ab:max><ab:mid="xyz:abc...@pqrs.com"/></wyty:ert>
HTH
R'
Subst and \" escaping are of course good solutions. My personal
favourite string substitution method when I have to deal with strings
containing special characters is [string map]:
string map [list %ABHI% $abhi] {<ab:max><ab:mid="%ABHI%"/></
wyty:ert>}
Of course since [string map] is straightforward byte-by-byte
translation you can choose any pattern to mark where you want the
substitution without affecting the rest of the string:
string map [list ... $abhi] {<ab:max><ab:mid="..."/></wyty:ert>}
I know HTML you can use single quotes instead of double quotes...not
sure if that works for you here or not, but it would look something
like:
set str "<ab:max><ab:mid='$abhi'/></wyty:ert>"
HTH,
--brett
But also the following will work:
set result "{<ab:max><ab:mid=\"$abhi\"/></wyty:ert>}"
Schelte.
--
set Reply-To [string map {nospam schelte} $header(From)]
You might want to omit the leading and trailing {} in this case.
R'
That depends how you interpret the question. Since the subject
indicated "quotes in braces" I assumed the OP wanted the braces.
Without that requirement the question would have been no challenge
at all ;-)
I assumed the OP wanted the quotes in braces, but not the braces in
quotes ;-)
Seriously, since the braces are not part of the string if the
set foo {...}
form is used, I would assume that if you use
set foo "..."
there should be no braces.
R'