2

只是一个简单但经常需要的操作 - 如何将字符串添加到变量:

set s "world!!!"
prepend s "Hello " #how to accomplish this effectively?
puts $s
#should print "Hello world!!!"
4

2 回答 2

5

你可以写一个程序prepend

proc prepend {s_var txt} {
  upvar 1 $s_var s
  set s "${txt}${s}"
}

这正是你想要的。但我认为通常写起来更简单:

set s "Hello ${s}"
于 2012-04-04T10:46:28.133 回答
3

自从我使用 TCL 已经有一段时间了,但是你有没有试过这个:

set s "world!"
set s "hello $s"
puts $s
于 2012-04-04T10:52:50.763 回答