_Vlad Posted April 20, 2020 Posted April 20, 2020 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
FrancescoDiMuro Posted April 20, 2020 Posted April 20, 2020 @_Vlad You could use FileWrite() instead of FileWriteLine(), since it adds automatically the carriage return/line feed to the end of the line. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
_Vlad Posted April 20, 2020 Author Posted April 20, 2020 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.
Nine Posted April 20, 2020 Posted April 20, 2020 Just check if the string's last 2 characters are @CRLF. Something like this should work : Local $sString = "Something that has a carriage return and line feed at the end" & @CRLF FileWrite("Test.txt", StringRight($sString,2) = @CRLF ? StringTrimRight($sString, 2) : $sString) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
Musashi Posted April 20, 2020 Posted April 20, 2020 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. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Subz Posted April 21, 2020 Posted April 21, 2020 Why not use StringStripWS($sString, 2) ;~ Removes trailing white space, you can also use _FileWriteToLine to write to a specific line.
Nine Posted April 21, 2020 Posted April 21, 2020 Good point @Subz Sometimes we forget about those “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now