How I add bracket in string variable in TCL file

前端 未结 2 874
小鲜肉
小鲜肉 2021-01-29 02:15

I have written one TCL script but I have one problem when making a string variable as below:

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

I want b

相关标签:
2条回答
  • 2021-01-29 02:43

    You just need to escape it:

    set a 100
    set b "this is variable\[$a\]"
    
    0 讨论(0)
  • 2021-01-29 02:44

    Other possibilities (but escaping the brackets is better):

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

    Documentation: set, format, subst

    0 讨论(0)
提交回复
热议问题