在TCL中连接/追加字符串

时间:2017-06-12 09:14:35

标签: string tcl

我正在尝试将文件名附加到TCL中的项目目录中:

set filename hello
set currentPath "D:/TEMP/project name/subfolder/"
puts [append $currentPath $filename]

根据docs所需要的只是我们要追加的varName以及?value附加到varName的{​​{1}}。不幸的是,当我运行上面的代码时,我只得到hello作为输出。如何在TCL上执行这个简单的任务?

1 个答案:

答案 0 :(得分:2)

问题是您在需要变量 name 的地方使用变量 value 。在Tcl中(与其他一些语言相反),$表示“读取此变量 now ”,这意味着您为append提供了一个相当奇怪的变量名称。尝试切换:

puts [append $currentPath $filename]

为:

puts [append currentPath $filename]
# Be aware that this *updates* the currentPath variable

另外,如果您使用它来制作文件名,请考虑使用file join代替;它处理你目前还没有意识到的各种棘手案例,这样你就不需要了解它们。

puts [file join $currentPath $filename]
相关问题