2016-10-11 85 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]來修復它。 –