Search the Community
Showing results for tags 'delete blank lines in txt'.
-
Friends,I can not delete blank lines in txt file TXT.txt File Line1 Line2 Line5 Line8 #include <array.au3> #include <file.au3> #include <String.au3> #include <StringConstants.au3> $Inputbox = InputBox("Enter", "Enter what you want to delete", "", "") If @error Then Exit If Not @error Then Global $File_to_written = @ScriptDir & "\" & "TXT.txt" Local $FileOpen = FileOpen($File_to_written, 2) If $FileOpen = -1 Then Exit MsgBox(17, 'ERROR', 'File open failed for output file') Local $ReadString = FileRead(@ScriptDir & "\OLD" & "\TXTOLD.txt") Local $aTXTSPLIT = StringSplit($ReadString, @CRLF, 3) For $1 = 0 To UBound($aTXTSPLIT) - 1 $ReadString = StringRegExpReplace($aTXTSPLIT[$1],$Inputbox, "") ;----------------------------These parts do not work--------- ;$ReadString = StringRegExpReplace($ReadString, '(?s)[\n\r\t\v]', '') ;$ReadString = StringRegExpReplace($ReadString, "(?m:^)\h*(\r\n|\r|\n)", "") ;$ReadString = StringRegExpReplace($ReadString, '(?m:^\s*[\r\n])', '') ;$ReadString = StringRegExpReplace($ReadString, '(?s)\r\n', '') ;---------------------------These parts do not work------------ $ReadString = StringStripWS($ReadString,8) FileWrite($FileOpen, $ReadString & @CRLF) Next FileClose($FileOpen) EndIf The following codes are working. But I want to do it with StringRegExpReplace Global $aLines _FileReadToArray($File_to_written, $aLines) For $i = $aLines[0] To 1 Step -1 If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf Next _FileWriteFromArray($File_to_written, $aLines, 1)