yucatan Posted August 28, 2008 Share Posted August 28, 2008 hi i have a file with 50 rules and on the 46 rule is standing a variable i wanne make that i can search to that variable and read that rule how i can do that ? so if on the 46 is standing hello that i can enter in a inbox hello and that he is going to search and he found on rule 46 the words hello and then he needs to read that whole line and show it to me how i can do that ? Link to comment Share on other sites More sharing options...
muhmuuh Posted August 28, 2008 Share Posted August 28, 2008 (edited) $word=InputBox("word", "word") $f=FileOpen("file.txt", 0) $br=0 While 1 $l = FileReadLine($f) If @error = -1 Then ExitLoop $br+=1 if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br) Wend FileClose($f) ? Edited August 28, 2008 by muhmuuh I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more. Link to comment Share on other sites More sharing options...
yucatan Posted August 28, 2008 Author Share Posted August 28, 2008 $word=InputBox("word", "word") $f=FileOpen("file.txt", 0) $br=0 While 1 $l = FileReadLine($f) If @error = -1 Then ExitLoop $br+=1 if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br) Wend FileClose($f) ? hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ? Link to comment Share on other sites More sharing options...
yucatan Posted August 28, 2008 Author Share Posted August 28, 2008 (edited) $word=InputBox("word", "word") $f=FileOpen("file.txt", 0) $br=0 While 1 $l = FileReadLine($f) If @error = -1 Then ExitLoop $br+=1 if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br) Wend FileClose($f) ? hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ? p.s. why i cant search @ line 1 he dont find what i search on line one? its not importend that i know with rule it is.. i just need to be able to read that entire rule that what i need find the line containing the words i look for and read that entire rule that what i need. Edited August 28, 2008 by yucatan Link to comment Share on other sites More sharing options...
Andreik Posted August 28, 2008 Share Posted August 28, 2008 Try this: #include <File.au3> $PATH = InputBox("FILE","Please select path",@ScriptDir & "\file.txt") $WORD=InputBox("WORD", "Search for word") $FILE=FileOpen($PATH, 0) For $INDEX = 1 To _FileCountLines($PATH) $LINE = FileReadLine($FILE,$INDEX) If StringInStr($LINE,$WORD,1) <> 0 Then Msgbox(0, "FOUND", "I found your word in line " & $INDEX) Next FileClose($FILE) When the words fail... music speaks. Link to comment Share on other sites More sharing options...
CrazyGenius Posted August 28, 2008 Share Posted August 28, 2008 hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ?p.s. why i cant search @ line 1 he dont find what i search on line one?Well there are a few ways to do it one is to read and display all lines$word=InputBox("word", "word")$f=FileOpen("file.txt", 0)$br=0While 1 $l = FileReadLine($f) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $l)WendFileClose($f)if lines are numbered you can searc the number line instead $word=InputBox("word", "word")$f=FileOpen("file.txt", 0)$br=0While 1 $l = FileReadLine($f) If @error = -1 Then ExitLoop $br+=1 if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br)WendFileClose($f)remembering line 1 will be 0 until it runs through the first timeeg file.txt containsHi MooNow$br will go$br = 0 (Hi)$br = 1 (Moo)$br = 2 (Now)just trial a few ways to search and display Link to comment Share on other sites More sharing options...
yucatan Posted August 28, 2008 Author Share Posted August 28, 2008 (edited) Well there are a few ways to do it one is to read and display all lines$word=InputBox("word", "word")$f=FileOpen("file.txt", 0)$br=0While 1 $l = FileReadLine($f) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $l)WendFileClose($f)if lines are numbered you can searc the number line instead $word=InputBox("word", "word")$f=FileOpen("file.txt", 0)$br=0While 1 $l = FileReadLine($f) If @error = -1 Then ExitLoop $br+=1 if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br)WendFileClose($f)remembering line 1 will be 0 until it runs through the first timeeg file.txt containsHi MooNow$br will go$br = 0 (Hi)$br = 1 (Moo)$br = 2 (Now)just trial a few ways to search and displaynice nice but i only need to search for a rule containing the word i enterd and then it need to read that entire line. thats what i need..how can i say to filereadline to read line 2 ? Edited August 28, 2008 by yucatan Link to comment Share on other sites More sharing options...
Andreik Posted August 28, 2008 Share Posted August 28, 2008 nice nice but i only need to search for a rule containing the word i enterd and then it need to read that entire line. thats what i need.. how can i say to filereadline to read line 2 ? FileReadLine($file,2) When the words fail... music speaks. Link to comment Share on other sites More sharing options...
CrazyGenius Posted August 28, 2008 Share Posted August 28, 2008 FileReadLine($file,2) theres that too Link to comment Share on other sites More sharing options...
yucatan Posted August 28, 2008 Author Share Posted August 28, 2008 FileReadLine($file,2) h mm okee i see i shall give it a try thx alot peopel. Link to comment Share on other sites More sharing options...
CrazyGenius Posted August 28, 2008 Share Posted August 28, 2008 h mm okee i see i shall give it a try thx alot peopel.just remember if you need to make it a variable you will be able to search it like in my second exampleif stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br) ; it will run till $br hits the same numberor you can just go$word=InputBox("word", "word")$f=FileOpen("file.txt", 0)$l = FileReadLine($f,$word)Msgbox(0, "found", "Contents of line " & $l)FileClose($f)and add inputbox to get a user typed file there are many ways to go about it Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now