Clovertech
› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › String map command
I am trying to do the following:
set data [string map {x $newx} $data]
I am getting literal “$newx” instead of the variable value.
I’ve played around with escapes and brackets and give up.
Try it with eval. Might work.
-- Max Drown (Infor)
Nevermind the eval comment. Here’s how you do it:
set data “x” set newx “Hello, World!” set data [string map [list x $newx] $data] echo $data
Thanks Max, I knew it was too easy.
Your origianal code did not work because the $ value was inside curly braces. It was interpreted as literal $newx
Had you done it like: set data [string map “x $newx” $data]
It would have worked as expected
I thought I tried double quotes. Oh well.
Also, I’m wondering where I came up with the curly braces in the first place. Seems to me that was the only way it would work once.
Thanks for the info Charlie.