繁体   English   中英

使用 TCL/TK 读取特定的行和列形成一个文件

[英]Read Specific line and columns form a file with TCL/TK

我想用 TCL/TK 从文件中读取一个单词并将其存储在一个变量中。

我想读取位于第 366 行和第 19 到 21 列的 file.txt 中的单词,并将其存储在字符串变量 Word 中。

set fp [open src.txt r]
set count 0
while {[gets $fp line]!=-1} {
    incr count
    if {$count==366} {
            break
    }
}
close $fp

puts "Required Line : $line"
set result [string range $line 18 20]
puts "Required word(s) : $result"

string range索引从 0 开始,所以我在每个索引中减少了 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM