Jump to content
Sign in to follow this  
d0n

better way to look for last line of text

Recommended Posts

d0n

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

Share this post


Link to post
Share on other sites
Hypertrophy

Why would you search from the bottom up?

Share this post


Link to post
Share on other sites
d0n

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

Share this post


Link to post
Share on other sites
enaiman

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

Share this post


Link to post
Share on other sites
d0n

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

Share this post


Link to post
Share on other sites
Malkey

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
;

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.