簡體   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