TCL:行以字符串字符开头,按原样打印行,不做任何更改
TCL: lines start with a string character, print the line as is without any changes
读取文件系统上名为 input.txt 的文件的 TCL 脚本;
set fp [open "input.txt" r]
while { [gets $fp data] >= 0 } {
puts $data
}
如何检查文件中的行是否以字符串字符开头并打印它们?
你是这个意思吗?
while {[gets $fp data] >= 0} {
if {[string match -nocase {[a-z]*} $data]} {
puts $data
}
}
见string match man page. You might also be interested in regexp
读取文件系统上名为 input.txt 的文件的 TCL 脚本;
set fp [open "input.txt" r]
while { [gets $fp data] >= 0 } {
puts $data
}
如何检查文件中的行是否以字符串字符开头并打印它们?
你是这个意思吗?
while {[gets $fp data] >= 0} {
if {[string match -nocase {[a-z]*} $data]} {
puts $data
}
}
见string match man page. You might also be interested in regexp