Hi, i'm looking for a function that find a string in a txt file.
If in my raiden.txt i have a string "hello", is in tcl a function that return 0 if it exists ?
Excuse my bad english.
Regards
Code: Select all
#Usage: [find:text <filename.txt> <search string>]
proc find:text {filename arg} {
set count "0"
set rfile [open "$filename" "r"]
while {![eof $rfile]} {
gets $rfile line
if {[string match "*[string map {\x20 *} $arg]*" $line]} {
putserv "PRIVMSG $nick :$line"
set count [expr $count+1]
return 1
}
}
close $rfile
if {$count == 0} {
return 0
}
}There's no variable called 'nick' in that proc. Also, returning from inside the loop will leave the file open (you must have meant 'break'Ofloo wrote:Code: Select all
#Usage: [find:text <filename.txt> <search string>] proc find:text {filename arg} { set count "0" set rfile [open "$filename" "r"] while {![eof $rfile]} { gets $rfile line if {[string match "*[string map {\x20 *} $arg]*" $line]} { putserv "PRIVMSG $nick :$line" set count [expr $count+1] return 1 } } close $rfile if {$count == 0} { return 0 } }
Code: Select all
#Usage: [find:text <nick> <filename.txt> <search string>]
proc find:text {nick filename arg} {
set count "0"
set rfile [open "$filename" "r"]
while {![eof $rfile]} {
gets $rfile line
if {[string match "*[string map {\x20 *} $arg]*" $line]} {
putserv "PRIVMSG $nick :$line"
set count [expr $count+1]
}
}
close $rfile
if {$count == 0} {
return 0
}
if {$count != 0} {
return 1
}
}