【发布时间】:2016-10-09 21:28:15
【问题描述】:
我在日志文件中放置了一个唯一 ID,我可以搜索该文件并获取它,一旦我在文件中找到唯一 ID,我需要在此唯一 ID 之后找到另一个字符串(将其命名为字符串 2)并复制字符串 2 的下一行。
请在下面找到我的功能,并建议如何实现。
Func getAuthResponse($LogfilePath, $AuthRespFilePath, $UniqueId, $search)
Global $iLine = 0, $sLine = ''
Global $hFile = FileOpen($LogfilePath)
If $hFile = -1 Then
MsgBox(0,'ERROR','Unable to open file for reading.')
Exit 1
EndIf ;If $hFile = -1 Then
; find the line that has the search string
While 1
$iLine += 1
$sLine = FileReadLine($hFile)
If @error = -1 Then ExitLoop
; finding the unique id in the log file
;ConsoleWrite($UniqueId & @LF)
If StringInStr($sLine, $UniqueId) Then
ConsoleWrite($sLine & @LF)
; assuming that unique id is found , now finding the phrase Auth response is as follow : after the unique id
$sNewLine = $sLine+
If StringInStr($sLine, $search) Then
ConsoleWrite($sLine & @LF)
//// SOME LOGIC ////
ExitLoop
EndIf ;If StringInStr($sLine, $search) Then
ExitLoop
EndIf ;If(StringInStr($sLine, $UniqueId) Then
WEnd ;While 1
FileClose($hFile)
EndFunc
【问题讨论】: