TCL : Concatenate a variable and a string

前端 未结 7 1554
有刺的猬
有刺的猬 2021-01-01 12:43

Assume we have a variable \'a\' set to 12345 :

set a 12345

Now how do i set a new variable \'b\' which contains the value of \'a\' and anot

相关标签:
7条回答
  • 2021-01-01 13:09

    I don't get what you mean the direct string... I'm not sure if you want... However, if you want the value of 12349876 you can do:

    % set b [concat $a$u]
    12349876
    

    If you want $a or $u to be part of the string, just add a backslash '\' before the desired variable.

    0 讨论(0)
  • 2021-01-01 13:09

    set myString "Hello"

    append myString " World!"

    puts "$myString"

    Hello World!

    0 讨论(0)
  • 2021-01-01 13:17

    Or,you can use format

    set b [format %s%s $a $u]

    0 讨论(0)
  • 2021-01-01 13:25

    other option is to use set command. since set a gives value of a we can use it to set value of b like below

    set b [set a]9876

    0 讨论(0)
  • 2021-01-01 13:27

    From Tcl 8.6.2 onwards, there is string cat which can be used to solve this problem.

    set b [string cat $a 9876]
    
    0 讨论(0)
  • 2021-01-01 13:32

    Other option is to use concat command like below.

    set b [concat $a\9876]

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