Here is a comparison of the functions.
Anyway here is my benchmark result:
str_getTailf (by Tuncay): 188
str_getTail (by Tuncay): 469
StrTail /loop (by strictlyfocused02): 16750
Tail /regex (by Laszlo): 1062
This is the script and the functions used to benchmark:
Text := "`n`n`n"
Loop, 100000
Text .= "`nLine " . A_Index
StartTime := A_TickCount
Loop, 100
str_getTailf(Text)
ElapsedTime1 := A_TickCount - StartTime
StartTime := A_TickCount
Loop, 100
str_getTail(Text)
ElapsedTime2 := A_TickCount - StartTime
StartTime := A_TickCount
Loop, 100
StrTail(1,Text)
ElapsedTime3 := A_TickCount - StartTime
StartTime := A_TickCount
Loop, 100
Tail(1,Text)
ElapsedTime4 := A_TickCount - StartTime
out =
(
str_getTailf (by Tuncay):`t`t%ElapsedTime1%
str_getTail (by Tuncay):`t`t%ElapsedTime2%
StrTail /loop (by strictlyfocused02):`t%ElapsedTime3%
Tail /regex (by Laszlo):`t`t%ElapsedTime4%
)
MsgBox, 1, Benchmark results, Ok copies to clipboard`n`n%out%
IfMsgBox Ok
Clipboard := out
RETURN
str_getTailf(ByRef _Str) {
Return SubStr(_Str,InStr(_Str,"`n",False,0)+1)
}
str_getTail(_Str, _LineNum = 1)
{
StringGetPos, Pos, _Str, `n, R%_LineNum%
StringTrimLeft, _Str, _Str, % ++Pos
Return _Str
}
StrTail(k,str) ;; Inspired by Laszlo (http://www.autohotkey.com/forum/topic6928.html)
{
Loop,Parse,str,`n
{
i := Mod(A_Index,k)
L%i% = %A_LoopField%
}
L := L%i%
Loop,% k-1
{
If i < 1
SetEnv,i,%k%
i-- ;Mod does not work here
L := L%i% "`n" L
}
Return L
}
Tail(k,str) {
Return RegExReplace(str,".*(?=(\n[^\n]*){" k "}$)")
}
edit: updated the Tail function from Laszlo