关于在tcl获得指挥权

关于在tcl获得指挥权,tcl,Tcl,我想打印下一行的字符: 说: 当文件中存在此变量dum=183时,打印下一行的下一个字符 注意:我使用的是tcl 谢谢,这将帮助您开始 一次处理一行文件的典型习惯用法是: 1行读: set f [open thefile.txt] while {[gets $f line] >= 0} { # work with the line of text in "line" } close $f 2带行拆分的块读取: set f [open thefile.txt] set text [

我想打印下一行的字符:

说:

当文件中存在此变量dum=183时,打印下一行的下一个字符

注意:我使用的是tcl


谢谢,

这将帮助您开始

一次处理一行文件的典型习惯用法是:

1行读:

set f [open thefile.txt]
while {[gets $f line] >= 0} {
    # work with the line of text in "line"
}
close $f
2带行拆分的块读取:

set f [open thefile.txt]
set text [read $f]
close $f
set lines [split [string trim $text] \n]
foreach line $lines {
    # work with the line of text in "line"
}
这可以通过使用包来简化:

package require fileutil
::fileutil::foreachLine line thefile.txt {
    # work with the line of text in "line"
}
另一种方法是使用正则表达式进行搜索和提取。这是最糟糕的方法,因为它缺乏灵活性,而且在使用中很可能会出现问题

set f [open thefile.txt]
set text [read $f]
close $f
# this regular expression is an example
if {[regexp {\ydum\y[^\n]*.(.)} $text -> thecharacter]} {
    # the character you wanted should be in "thecharacter"
}
文件: , , , , , , , , , , , , , ,

谢谢你的帮助!