TCL:连接一个变量和一个字符串 [英] TCL : Concatenate a variable and a string
本文介绍了TCL:连接一个变量和一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们有一个变量 'a' 设置为 12345 :
Assume we have a variable 'a' set to 12345 :
set a 12345
现在我如何设置一个新的变量 'b',它包含 'a' 的值和另一个字符串说 9876
Now how do i set a new variable 'b' which contains the value of 'a' and another string say 9876
解决方法类似于
set a "12345"
set u "9876"
set b $a$u
但我不想指定 $u
而是我想要使用直接字符串..
but i dont want to specify $u
instead i want the direct string to used..
推荐答案
您可以:
set b ${a}9876
或者,假设 b
设置为空字符串或未定义:
or, assuming b
is either set to the empty string or not defined:
append b $a 9876
当 $a
很长时,对 append
的调用效率更高(参见 append
doc).
The call to append
is more efficient when $a
is long (see append
doc).
这篇关于TCL:连接一个变量和一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文