I want to read a word from a file with TCL/TK and store it in a variable.
I want to read the word which is located in the file.txt which is located in line number 366 and columns from 19 to 21 and store it in the string variable 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
indices starting with 0, so I have reduced 1 in each indices
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.