2016-10-11 90 views
0

我写了一个TCL脚本,但做如下字符串变量时,我有一个问题,TCL文件添加支架:我如何在字符串变量中

set a 100 
set b "this is variable[$a]" 

我希望B与B =“this is variable[100]被分配“但我得到了错误:

 
invalid command name 100 

请帮我解决它:-(

+0

参见(HTTP的[Tcl的12个语法规则]:// TCL .tk/man/tcl8.6/TclCmd/Tcl.htm),特别是规则#7 –

回答

2

你只需要逃避它:

set a 100 
set b "this is variable\[$a\]" 
+0

从技术上讲,我们只需要跳过左括号。 –

+0

非常感谢。我的问题是我使用了与TCL相同的工具,但它不接受\ [和\]作为字符串“[]”。 –

0

其它可能性(但是逸出括号为佳):

set b [format {this is variable[%d]} $a] 
set b [subst -nocom -noback {this is variable[$a]}] 

文档: setformatsubst

+0

非常感谢。我通过使用set b [format {this是变量[%d]} $ a]来修复它。 –