只是一个简单但经常需要的操作 - 如何将字符串添加到变量:
set s "world!!!"
prepend s "Hello " #how to accomplish this effectively?
puts $s
#should print "Hello world!!!"
最佳答案
你可以编写一个过程prepend
:
proc prepend {s_var txt} {
upvar 1 $s_var s
set s "${txt}${s}"
}
这正是您想要的。但我认为通常写起来更简单:
set s "Hello ${s}"
关于string - TCL 字符串前置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10009181/