d0n Posted July 28, 2009 Share Posted July 28, 2009 Right now i have this, it will basically search from the bottom up till it finds the text i am looking for. is there a better way to do this? For $i = 1 To $aLines[0];<== Look for last line $a = $aLines[0] - $i $aTime2 = StringRegExp($aLines[$a], $Time, 1) If $aTime2 <> 0 Then MsgBox("","",$aTime2[0]&":"&$aTime2[1]&":"&$aTime2[2]) $i = $aLines[0] EndIf Next Link to comment Share on other sites More sharing options...
Hypertrophy Posted July 28, 2009 Share Posted July 28, 2009 Why would you search from the bottom up? Link to comment Share on other sites More sharing options...
d0n Posted July 28, 2009 Author Share Posted July 28, 2009 because i want to get the last line of text, or should i be setting offset to -1? is that from bottom up? Link to comment Share on other sites More sharing options...
enaiman Posted July 28, 2009 Share Posted July 28, 2009 because i want to get the last line of text, or should i be setting offset to -1? is that from bottom up?"get" ...what?- the last line number?- the last line content?Last line number: _FileCountLines($sFilePath)Last line content: FileReadLine($sFilePath, _FileCountLines($sFilePath)) SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
d0n Posted July 28, 2009 Author Share Posted July 28, 2009 This is at the end of the txt file, problem is sometimes there are extra space at the end so the last line isn't always the one i want [3:39:03 PM Jul 27 2009] i want to get the time, which is why i have the stringregexp thx Link to comment Share on other sites More sharing options...
Malkey Posted July 28, 2009 Share Posted July 28, 2009 You could try this method. Note: StringStripWS is used here to strip all trailing white spaces from the search string or file. ; #cs ;====== Using File Example =================== Local $sFile = "C:\PROGRA~1\AutoIt3\au3check.dat" $sREResult = StringRegExpReplace(StringStripWS(FileRead($sFile), 2), "(.*\v+)+(.+)\v*$", "\2") ; returns string of last line of file MsgBox(0, "Last Line", $sREResult) ; ============================================ #ce ; OR ;#cs ; =======Using String Example ================ Local $sStr = "First line" & @CRLF & "Second line" & @LF & "penultimate line" & @CR & "[3:39:03 PM Jul 27 2009]" & @CRLF & @CRLF $sREResult = StringRegExpReplace(StringStripWS($sStr, 2), "(.*\v+)+(.+)\v*$", "\2") ; returns string of last line of String MsgBox(0, "Last Line Example", "Text:" & @CRLF & $sStr & @LF & "-------------------------------" & @CRLF & _ "Last line: " & $sREResult) ; ============================================ ;#ce ; 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