阅读特定的行和列形成一个文件 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
我想用 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