Tcl 字符串转义
嘿呼,
现在我需要将像“[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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第一项,使用
{}
作为字符串分隔符以防止命令替换(这就是双引号字符串中的 [] 所发生的情况)对于第二项,
split
创建一个列表,而不是一个数组。使用lindex
对其进行索引:获取 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)On the second item,
split
creates a list, not an array. Index into it withlindex
:The best website for tcl info is the Tcler's Wiki at http://wiki.tcl.tk/