如何在TCL中打印一些操作的串联

发布于 2024-10-29 23:10:21 字数 270 浏览 0 评论 0原文

假设有这样的代码:

set val "Hello"
set listA {}

lappend listA 6 7

现在我想输入以下内容:

puts "${val} user! Your list contains two values. First is [lindex $listA 0] and the second is [lindex $listA 1]"

我怎样才能做到这一点?

Say there is a code like this:

set val "Hello"
set listA {}

lappend listA 6 7

Now I want to puts the following:

puts "${val} user! Your list contains two values. First is [lindex $listA 0] and the second is [lindex $listA 1]"

How I can do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽梦紫曦~ 2024-11-05 23:10:21

我不完全确定我理解是否正确。但是你所做的应该可以工作,只需稍作修改:

set val "Hello"
set listA {6 7}
# or:
# set listA {}
# lappend listA 6 7
puts "${val} user! Your list contains two values. First is [lindex $listA 0] and the second is [lindex $listA 1]"

给出输出:

Hello user! Your list contains two values. First is 6 and the second is 7

I'm not fully sure if I understood correctly. But what you did should work, with a small modification:

set val "Hello"
set listA {6 7}
# or:
# set listA {}
# lappend listA 6 7
puts "${val} user! Your list contains two values. First is [lindex $listA 0] and the second is [lindex $listA 1]"

Gives the output:

Hello user! Your list contains two values. First is 6 and the second is 7
初雪 2024-11-05 23:10:21

好的,我已经找到答案了。问题在于,在我的实际代码中,我使用“[”和“]”符号作为字符串,但没有“\”。

所以我需要写:

puts "Zone No ${key} has Range\[ [lindex $value 0] - [lindex $value 1] \]"

抱歉这个问题。

Ok, I have found the answer. The problem was in the fact that in my actual code I was using "[" and "]" symbols as a string but without "\".

So I need to write:

puts "Zone No ${key} has Range\[ [lindex $value 0] - [lindex $value 1] \]"

Sorry for the question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文