RegReplace last `n line

Get help with using AutoHotkey and its commands and hotkeys
maitresin
Posts: 25
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: 1479
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

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 7 Ultimate | Editor: Notepad++
My Personal Function Library | Check Out My Computer Rig
just me
Posts: 6526
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: 204
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”

Who is online

Users browsing this forum: AlexV, Bing [Bot], Chunjee, flipmania, Google [Bot], Odlanir, ttttt, v3Van and 227 guests