GoogleDude Posted September 14, 2006 Share Posted September 14, 2006 Sorry if this question has been asked before but! I searched the Help and all I came up with is "StringInStr" But I wasnt sure if that is what I am looking for or not? How can I search for a string of text in a TXT file and set the found string as a $var? Sorry for the beginner questions! GoogleDude Link to comment Share on other sites More sharing options...
cppman Posted September 14, 2006 Share Posted September 14, 2006 (edited) well, about the setting $var as the found string would be useless since you already know what the string you are searching for and "hoping" to return anyways. but here is a way it can be done. #include <file.au3> #include <array.au3> Func _StringInFile($file, $string) Local $avLines[_FileCountLines($file)] _FileReadToArray($file, $avLines) For $i = 1 to $avLines[0] if (StringInStr($avLines[$i], $string)) Then Return True Else EndIf Next Return False EndFunc Edited September 14, 2006 by CHRIS95219 Miva OS Project Link to comment Share on other sites More sharing options...
GoogleDude Posted September 14, 2006 Author Share Posted September 14, 2006 Thanks for the fast reply! Well the thing is the string may vary, IE... I am looking for any word that contains the word "test" kinda like a wildcard search! so it may return "testing123" and if it does then "testing123" should be set as the var. Does that change anything? GoogleDude Link to comment Share on other sites More sharing options...
cppman Posted September 14, 2006 Share Posted September 14, 2006 (edited) Func _StringInFile($file, $string) Local $avLines[_FileCountLines($file)] _FileReadToArray($file, $avLines) For $i = 1 to $avLines[0] if (StringInStr($avLines[$i], $string)) Then $words = StringSplit($avLines[$i], " ") for $x = 1 to $words[0] if (StringInStr($words[$x], $string)) Then Return $words[$x] Else EndIf Next Else EndIf Next Return False EndFunc This work? Edited September 14, 2006 by CHRIS95219 Miva OS Project Link to comment Share on other sites More sharing options...
GoogleDude Posted September 14, 2006 Author Share Posted September 14, 2006 (edited) Thanks a ton, but one more dumb/noob question. Where do I put my "string" to search for and the "TXT file" and location to search? Thanks again for your prompt response. I hope some day I can be as helpfull as you and the others on this forum. GoogleDude Edited September 14, 2006 by GoogleDude Link to comment Share on other sites More sharing options...
cppman Posted September 14, 2006 Share Posted September 14, 2006 your welcome you can use the function like this: #include <file.au3> #include <array.au3> $data = _StringInFile("test.txt", "mystring") msgbox(0, "", $data) Miva OS Project Link to comment Share on other sites More sharing options...
GoogleDude Posted September 14, 2006 Author Share Posted September 14, 2006 Well HooRahh for me. Thanks to you! That did just the trick. Thanks again. GoogleDude Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 14, 2006 Moderators Share Posted September 14, 2006 (edited) What's the sense of _FileCountLines() if you are using _FileReadToArray()? Edit: Sorry... this is what I meant didn't make sense:Func _StringInFile($file, $string) Local $avLines[_FileCountLines($file)] _FileReadToArray($file, $avLines) For $i = 1 to $avLines[0] if (StringInStr($avLines[$i], $string)) Then $words = StringSplit($avLines[$i], " ") for $x = 1 to $words[0] if (StringInStr($words[$x], $string)) Then Return $words[$x] Else EndIf Next Else EndIf Next Return False EndFunc This work? Edited September 14, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
GoogleDude Posted September 14, 2006 Author Share Posted September 14, 2006 Sorry again for the NOOB question AGAIN, but I am having a problem adding the "string" to a RunWait command! This is what I am trying but it isnt working. The SC window pops up but its saying "wrong arguments". RunWait(@ComSpec & " /c " & 'sc delete' & $var ) Am I missing the correct syntex for the RunWait function? Also, Can you put a Function inside a Function? Thanks again. GoogleDude Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 14, 2006 Moderators Share Posted September 14, 2006 Try a space after delete. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
cppman Posted September 15, 2006 Share Posted September 15, 2006 (edited) What's the sense of _FileCountLines() if you are using _FileReadToArray()?Edit:Sorry... this is what I meant didn't make sense:because _FileReadToArray does'nt return an array, you have to pass the "already made" array by reference.and so the array is the right size that _FileReadToArray will be using...?btw, I don't like declaring arrays without a set element amount(unless absolutely unneeded), helps me feel more organized... Edited September 15, 2006 by CHRIS95219 Miva OS Project 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