Forum OpenACS Q&A: How do I parse a string of the form "some @var_1@ text @var_2@ here" where the var_i's are stored in a tcl array or elsewhere?

I'm trying to write a flexible log message generator with callbacks which provide named pieces of the log messages, which get included in the final log message if they appear in a format string.
The most simple approach is most probably this:

  set dict(@var_1@) substituted
  set dict(@var_2@) appears
  set string "some @var_1@ text @var_2@ here"
  puts [string map [array get dict] $string]

which prints out "some substituted text appears here"

Gustaf:

Thanks! I used this approach almost exactly; works fine!