Search Text to Get Line of First Match
I am looking for a simple function to search a certain text file for a string and return the line where the first match is found. I've looked on the wiki but found no function to serve this purpose.
5 posts
Name "Output"
OutFile "Output.exe"
!include "TextFunc.nsh"
!insertmacro LineFind
!include "WordFunc.nsh"
!insertmacro WordFind
Section
StrCpy $R0 "MyString" #String for search
StrCpy $R1 "" #Result line
${LineFind} "C:\a.log" "/NUL" "1:-1" "LineFindCallback"
IfErrors 0 +2
MessageBox MB_OK "Error"
MessageBox MB_OK "$$R1={$R1}"
SectionEnd
Function LineFindCallback
${WordFind} '$R9' '$R0' 'E+1{' $1
IfErrors end
StrCpy $R1 $R8
StrCpy $0 StopLineFind
end:
Push $0
FunctionEnd