Jump to content

Recommended Posts

Posted

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
Posted

because i want to get the last line of text, or should i be setting offset to -1? is that from bottom up?

Posted

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 :)

Posted

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

Posted

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
;

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...