spoolin1 Posted December 4, 2019 Share Posted December 4, 2019 (edited) $file = FileOpen("file.txt", 0) $read = FileRead($file) If @error = -1 Then MsgBox(0, "Error", "File not read") Exit Else ;;;MsgBox(0, "Read", $read) If StringRegExp($read, "______Part Status______") Then MsgBox(0, "Oops", "Match") Else MsgBox(0, "Oops", "No match") EndIf EndIf FileClose($file) I found this code and works great finding a string. What I would like to do is have it look at the next line after a string and assign it to a variable then go from there. End goal is to check if there is any text on the next line after string or if its empty. Edited December 4, 2019 by spoolin1 Link to comment Share on other sites More sharing options...
Nine Posted December 4, 2019 Share Posted December 4, 2019 Instead of using StringRegExp use StringInStr that will give you the position of the string and then calculate how long is the searched string and see what's after that with StringMid. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 5, 2019 Moderators Share Posted December 5, 2019 spoolin1, Or read the file into an array (_FileReadToArray) and then search the array - when you find the match you just need to read the next element. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Malkey Posted December 5, 2019 Share Posted December 5, 2019 An example using StringRegExpReplace():- ; ---- Create a test text file ------ Local $sText = "", $sOutFile = "output.txt" For $i = 1 To 6000 $sText &= (Mod($i, 100) ? "Line " & StringRight("0000" & $i, 4) : "") & @CRLF ; Every 100th line is blank. Next FileWrite($sOutFile, $sText) ;ConsoleWrite($sText & @CRLF) ; -------- Find the next line ---------- Local $sSearch = "Line 2999" ; The next line will be blank. ;Local $sSearch = "line 2995" ; The next line will be non-blank. (Remove leading comment character at start of this line to test) Local $sNextLine = StringRegExpReplace(FileRead($sOutFile), "(?is)^.*" & $sSearch & "\R([^\v]*).*$", "$1") ; Case insensitive "(?i)" MsgBox(0, "Next line", 'The next line after the line, "' & $sSearch & ' is ' & ($sNextLine = "" ? "blank." : @CRLF & '"' & $sNextLine & '".')) If FileExists($sOutFile) Then FileDelete($sOutFile) ; Clean up the created test text file. Link to comment Share on other sites More sharing options...
mikell Posted December 5, 2019 Share Posted December 5, 2019 Be careful with regex which needs precise requirements : is the string a part of the line or the whole line, can several occurences of the string exist in the file, is a line considered as 'empty' even when containing only white spaces, etc 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