Clever1mba Posted June 13, 2005 Share Posted June 13, 2005 (edited) hi #include <file.au3>Dim $aRecordsIf Not _FileReadToArray("test.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) ExitEndIfFor $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x])Nexthow to search text in .txt file i think this method StringinStr($Source, "Keyword")should be use but donno wat exactly to do if u any have any idea then plz let me know or any example of search in text file using keyword Edited June 13, 2005 by asimzameer Link to comment Share on other sites More sharing options...
ezzetabi Posted June 13, 2005 Share Posted June 13, 2005 may help $h = 'filename.txt' $r = 'string to seek' $f = FileRead($h, FileGetSize($h)) msgbox(32, 'Position:', StringInStr($r, $f)) Link to comment Share on other sites More sharing options...
Valuater Posted June 13, 2005 Share Posted June 13, 2005 (edited) OK... you really try and I had a similar problem just recently First in your other posts, you were reading in 1 character at a time Second You really want to find Time:... in your text files Third now you are reading into an array.... but want to use $StringinStr() there is a difference A string is not an array (according to Autoit and the functions) So... maybe you could work with something like this.... Its not perfect.... but this is newer ground for me too I just noticed you keep trying $Text = "text.txt" ; location of text file $NFile = FileOpen($Text, 0) ; Check if file opened for reading OK If $NFile = -1 Then MsgBox(0, "Error", "Unable to open file.") EndIf Dim $Data_[101], $newID="" ; to set-up for an array - if you want an array ; Read in lines of text until the EOF is reached While 1 $NLine = FileReadLine($NFile) If @error = -1 Then ExitLoop If $NLine <> "" Then ; for a string if StringInStr( $NLine, "Date:") Then $DLine = $NLine ConsoleWrite ($DLine & @CR) ; sends it to the bootom of this screen - change to send it ??????? EndIf ; for an array $newID = $newID + 1 ; number for an array $Data_[$newID] = $NLine ; creates the line as an array MsgBox(0,"TEST"," Num = " & $newID & @CRLF & " String = " & $NLine & @CRLF & " Array = " & $Data_[$newID] & @CRLF & " Date = " & $DLine) EndIf WEnd FileClose($NFile) ********** i cannot test this ************ You need to test and tweak this for your applications Hope it helps........ ( and works) 8) Edited June 13, 2005 by Valuater Link to comment Share on other sites More sharing options...
Valuater Posted June 14, 2005 Share Posted June 14, 2005 i tested it here and it worked for me Dim $DLine $Text = @HomeDrive & "\Temp\text.txt"; location of text file ;^^^^^ YOU NEED TO SET THIS LOCATION ABOVE ^^^^ $NFile = FileOpen($Text, 0) ; Check if file opened for reading OK If $NFile = -1 Then MsgBox(0, "Error", "Unable to open file.") EndIf Dim $Data_[101], $newID=""; to set-up for an array - if you want an array ; Read in lines of text until the EOF is reached While 1 $NLine = FileReadLine($NFile) If @error = -1 Then ExitLoop If $NLine <> "" Then ; for a string if StringInStr( $NLine, "Date:") Then $DLine = $NLine ConsoleWrite ($DLine & @CR); sends it to the bootom of this screen - change to send it ??????? EndIf ; for an array $newID = $newID + 1; number for an array $Data_[$newID] = $NLine; creates the line as an array MsgBox(0,"TEST"," Num = " & $newID & @CRLF & " String = " & $NLine & @CRLF & " Array = " & $Data_[$newID] & @CRLF & " Date = " & $DLine) EndIf WEnd FileClose($NFile) as stated previously **** You need to test and tweak this for your applications ***** my test worked fine!! showed all information and displayed the date info on the bottom of my screen my text.txt .................................... how are you Date: 2-15-05 i am fine Date: 3-15-05 i left you a message Date: 5-15-05 .................................... good luck 8) Link to comment Share on other sites More sharing options...
Valuater Posted June 14, 2005 Share Posted June 14, 2005 Nice try... look at the note for setting data you put in This works expandcollapse popup#include <Array.au3> #include <GUIConstants.au3> GUICreate("TEST SEARCH") $myedit=GUICtrlCreateEdit (""& @CRLF, 1,50,400,300,$ES_AUTOVSCROLL+$WS_VSCROLL) GUISetState () Sleep(50) Dim $DLine $Text = "test.txt" ;^^^^^ YOU NEED TO SET THIS LOCATION ABOVE ^^^^ ;$Text = @HomeDrive & "\Temp\text.txt"; this line is for me $NFile = FileOpen($Text, 0) ; Check if file opened for reading OK If $NFile = -1 Then MsgBox(0, "Error", "Unable to open file.") EndIf Dim $Data_[101], $newID=""; to set-up for an array - if you want an array ; Read in lines of text until the EOF is reached While 1 $NLine = FileReadLine($NFile) If @error = -1 Then ExitLoop If $NLine <> "" Then ; for a string if StringInStr( $NLine, "Date:") Then $DLine = $NLine ;ConsoleWrite ($DLine & @CR); sends it to the bootom of this screen - change to send it ??????? Send($Dline & @CRLF) Sleep(50) EndIf ;GUICtrlSetData( $myedit, $DLine)>>>>>>>>>>>>>>> this line changes the data... it does not ad to it EndIf WEnd FileClose($NFile) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend ok.... Enjoy! 8) Link to comment Share on other sites More sharing options...
Valuater Posted June 14, 2005 Share Posted June 14, 2005 (edited) -------------- Your last post does not reflect my corrections ----------------- asimzameer Today, 08:12 PM Post #9 Advanced Member Group: Members Posts: 124 Joined: 10-January 05 Member No.: 4334 And how did you get to be an "Advanced Member" ???? Edited June 14, 2005 by Valuater 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