开发者

Tcl string escape

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 Questio开发者_StackOverflow中文版n 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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜