sosimple Posted November 10, 2007 Share Posted November 10, 2007 Hi, can anyone help on this because i dont have much expiriance on files.. I have a file myfile.txt with words. I need a script serching for a word in there . For example serching for the word animal . I only need to tell me if there is the word there, nothing else. Thanks, Link to comment Share on other sites More sharing options...
searchresult Posted November 10, 2007 Share Posted November 10, 2007 (edited) Hi, can anyone help on this because i dont have much expiriance on files.. I have a file myfile.txt with words. I need a script serching for a word in there . For example serching for the word animal . I only need to tell me if there is the word there, nothing else. Thanks, here is the code #include <array.au3> $FileLoad = Fileread("file.txt") $WordLoad = StringSplit($FileLoad, " ") $Input = InputBox("Word Search", "Please insert word to search") $SearchResult = _ArraySearch($WordLoad, $Input) If $SearchResult = True Then MsgBox(0,"Search Rersult", "Word exists") Else MsgBox(48,"Error", "Word doesn't exist") EndIf Edited November 10, 2007 by searchresult Link to comment Share on other sites More sharing options...
BrettF Posted November 10, 2007 Share Posted November 10, 2007 Another method: $file = FileOpenDialog ("Open Wordlist", "", "TXT DOCUMENTS (*.txt)") $search = InputBox ("Search Term", "Enter a term to search the file for", "", " M") $hFile = FileOpen ($file, 0) $text = FileRead ($hFile) FileClose ($hFile) If StringInStr ($text, $search) <> @error Then MsgBox (0, "Success!", "String was found") Else MsgBox (0, "Error!", "String was not found") EndIf Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
ResNullius Posted November 10, 2007 Share Posted November 10, 2007 here is the code #include <array.au3> $FileLoad = Fileread("file.txt") $WordLoad = StringSplit($FileLoad, " ") $Input = InputBox("Word Search", "Please insert word to search") $SearchResult = _ArraySearch($WordLoad, $Input) If $SearchResult = True Then MsgBox(0,"Search Rersult", "Word exists") Else MsgBox(48,"Error", "Word doesn't exist") EndIfThis code would need a modification to work properly. The function for _ArraySearch statesReturn Value(s): On Success - Returns the position of an item in an array. On Failure - Returns an -1 if $vWhat2Find is not foundSo in your example, not found evaluates to -1 which equals true which means found... Not! The If line should be If $SearchResult > 0 Then Having said that, I favour Bert's example; should be faster. Link to comment Share on other sites More sharing options...
sosimple Posted November 10, 2007 Author Share Posted November 10, 2007 Thanks alot!! This is ok for what i am doing! 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