Page 1 of 1

RegReplace last `n line

Posted: 08 Apr 2018, 21:41
by maitresin
Why does it delete my last line of value and my last `n ?

Is not supose to delete only last blank line `n ?

Code: Select all

FileRead, FileContents, ID.txt
FileDelete, ID.txt
FileAppend, % RegExReplace(FileContents, "\v+\V+\v*$"), ID.txt

Re: RegReplace last `n line

Posted: 08 Apr 2018, 23:42
by Masonjar13
No, you're selecting the previous lines' new line, plus any non-vertical white space, then maybe more vertical white space, and the end of the string. I don't know exactly what you're going for, but \v*$should work to ensure the last line contains content by removing any blank lines at the end. This won't account for lines if they contain other white space, for which you may use [\v\s]*$.

Re: RegReplace last `n line

Posted: 09 Apr 2018, 03:51
by just me
If you want to remove 'empty' lines at the end of the file

Code: Select all

RTrim(FileContents, "`r`n")
might do it (see Trim).

Re: RegReplace last `n line

Posted: 09 Apr 2018, 06:13
by Cuadrix

Code: Select all

FileRead, FileContents, ID.txt
FileContents := RTrim(SubStr(Out, 1, - 1), "`r") ; Delete last blank line
FileDelete, ID.txt
FileAppend, FileContents, ID.txt