[英]concatenating/appending strings in TCL
I am trying to append a file name to a project directory in TCL: 我试图将文件名附加到TCL中的项目目录中:
set filename hello
set currentPath "D:/TEMP/project name/subfolder/"
puts [append $currentPath $filename]
According to the docs all that is needed is a varName
to which we are appending and a ?value
which is getting appended to varName
. 根据该文件所有需要的是一个
varName
,这是我们的追加和?value
这是越来越追加到varName
。 Unfortunately when I run the above code I only get hello
as output. 不幸的是,当我运行上面的代码时,我只会得到
hello
。 How can I perform this simple task on TCL? 如何在TCL上执行此简单任务?
The problem is that you're using the variable value where you need the variable name . 问题是您在需要变量名的地方使用了变量值 。 In Tcl (as opposed to some other languages), the
$
means “read this variable now ” and that's meaning that you're giving a rather odd variable name to append
. 在Tcl的(相对于其他一些语言)中,
$
表示“ 现在看这个变量”而这意味着你给一个相当奇怪的变量名append
。 Try switching from: 尝试从以下位置切换:
puts [append $currentPath $filename]
to: 至:
puts [append currentPath $filename]
# Be aware that this *updates* the currentPath variable
Also, if you're using this to make a filename, do consider using file join
instead; 另外,如果您使用此文件名来创建文件名,请考虑改用
file join
。 it handles all sorts of tricky cases you're not currently aware of so that you don't ever need to become aware of them. 它可以处理您当前不知道的各种棘手的情况,因此您无需知道它们。
puts [file join $currentPath $filename]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.