;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfGetLineOfStringInFile (strFilename, strSearch, intStart, intDirection, blnMatchCase) ; The FileGet version. If strSearch == "" Then Return 0 intFileSize = FileSize (strFilename) If intFileSize == 0 Then Return 0 If intStart < 1 Then Return 0 If intStart > intFileSize Then Return 0 strFile = FileGet (strFilename) If !!blnMatchCase intPos = StrIndex (strFile, strSearch, intStart, intDirection) Else intPos = StrIndexNC (strFile, strSearch, intStart, intDirection) EndIf If !!intPos Then Return 1 + StrCnt (strFile, @CRLF, 1, intPos, 1) Return 0 ;.......................................................................................................................................... ; Detlev Dalitz.20110716. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. DirChange (DirScript ()) strFilename = IntControl (1004, 0, 0, 0, 0) ; We use this file as test input. strMsgTitle = "Demo: udfGetLineOfStringInFile" ; Test1. strSearch = "Test" intStart = 1 intLine = udfGetLineOfStringInFile (strFilename, strSearch, intStart, @FWDSCAN, @TRUE) If !!intLine strMsgText = StrCat ("String found: ", strSearch : @LF : "Line: ", intLine) Else strMsgText = StrCat ("String not found: ", strSearch) EndIf Message (strMsgTitle, strMsgText) ; Test2. strSearch = "Test" : 3 intStart = 1 intLine = udfGetLineOfStringInFile (strFilename, strSearch, intStart, @FWDSCAN, @TRUE) If !!intLine strMsgText = StrCat ("String found: ", strSearch : @LF : "Line: ", intLine) Else strMsgText = StrCat ("String not found: ", strSearch) EndIf Message (strMsgTitle, strMsgText) :CANCEL Exit