RegReplace last `n line

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

RegReplace last `n line

08 Apr 2018, 21:41

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
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: RegReplace last `n line

08 Apr 2018, 23:42

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]*$.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: RegReplace last `n line

09 Apr 2018, 03:51

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).
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: RegReplace last `n line

09 Apr 2018, 06:13

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 188 guests