Tcl 字符串转义

发布于 2024-11-27 12:41:54 字数 357 浏览 5 评论 0原文

嘿呼,

现在我需要将像“[INTENSITY]”这样的字符串与 $line 进行比较。 ATM 我想这样做

if { [string compare "[INTENSITY]" $line] == 0 } { }

,但我认为“[”和“]”有问题。但我怎么能逃脱呢? 我在网上找不到一本好书或一个非常好的网站。

下一个问题是我创建了一个数组,就像

set data [split $file_data "\n"]

为什么我可以说 array stat $data ???

希望你能再次帮助我。

Heyhoo,

now i need to compare a String like "[INTENSITY]" to $line. ATM i want to do it like

if { [string compare "[INTENSITY]" $line] == 0 } { }

but i think there is a problem with the "[" and the "]". But how could i escape it ?
I could not find a good book or a really good website online.

Next Question is i created an array like

set data [split $file_data "\n"]

why i coulnd say array stat $data ???

Hope you could help me again.

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

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

发布评论

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

评论(1

总以为 2024-12-04 12:41:54

对于第一项,使用 {} 作为字符串分隔符以防止命令替换(这就是双引号字符串中的 [] 所发生的情况)

if { [string compare {[INTENSITY]} $line] == 0 } { }

对于第二项,split创建一个列表,而不是一个数组。使用 lindex 对其进行索引:

set data [split $file_data "\n"]
puts [lindex $data 1]

获取 tcl 信息的最佳网站是 Tcler 的 Wiki,网址为 http://wiki.tcl.tk /

For the first item, use {} as string delimiters to prevent command substitution (which is what happens with [] in a double-quoted string)

if { [string compare {[INTENSITY]} $line] == 0 } { }

On the second item, split creates a list, not an array. Index into it with lindex:

set data [split $file_data "\n"]
puts [lindex $data 1]

The best website for tcl info is the Tcler's Wiki at http://wiki.tcl.tk/

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