Jump to content

Recommended Posts

Posted

Hello Autoit,

I have a problem with FileWriteLine trying to remove the last blank line that this function adds.

I don't understand why is it so hard to remove the last blank line. if I put the text in an array then the last line will not show up or if I try to count the lines with _FileCountLines the last line it will not take in count. How can I remove this simple line, without using _FileWriteToLine.

 

Thank you!

Regards

Posted

Yes it would have been a good solution, but this will not work if I want to copy a file from one point to another that has already a blank line.

Posted
Posted
Local $hFileOpen, $sText, $sTextNew = ""
$sText = "This is Line 1" & @CRLF & "This is Line 2" & @LF & "This is Line 3" & @CR & "This is the last Line" & @CRLF
$sTextNew = StringRegExpReplace($sText, "(?m)\.*?\R$", "")
$hFileOpen = FileOpen(@ScriptDir & "\testfile.txt", 2) ; 2 = $FO_OVERWRITE
FileWrite($hFileOpen, $sTextNew)
FileClose($hFileOpen)

This would remove @CRLF as well as @LF or @CR at the end of the last line.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...