AutoIt – Remove Blank Lines

email me

; Remove blank lines from a File
Local $sString = "I am a string" & @CRLF & @CRLF & _
"With Empty Lines" & @CRLF & @CRLF & _
"Please Remove those empty lines"

MsgBox(4096, "Before", $sString)

$sString = _StringReplaceBlank($sString, 1)

MsgBox(4096, "Replaced: " & @extended & " lines.", $sString)

Func _StringReplaceBlank($sString, $sSpaces = "")
If $sSpaces Then
$sSpaces = "\s*"
EndIf

$sString = StringRegExpReplace($sString, "(?s)\r\n" & $sSpaces & "\r\n", @CRLF)

If @extended Then
Return SetError(0, @extended, $sString)
EndIf

Return SetError(1, 0, $sString)
EndFunc ;>_StringReplaceBlank