How to remove empty lines?
;==========================================================================================================================================
;
; How to remove leading or trailing @CRLF's from a text variable or a text file?
;
; How to remove empty lines - leading - trailing - leading and trailing.
;
; Detlev Dalitz.20101218.20101219.
;==========================================================================================================================================


; Remove one leading @CRLF from a string variable.
strMyVariable = @CRLF : "abc"
strMyVariable = StrSub (strMyVariable, 3, -1)


; Remove one leading @CRLF from a string variable.
strMyVariable = @CRLF : "abc"
strMyVariable = ItemRemove (1, ItemRemove (1, strMyVariable, @CR), @LF)



; Remove one trailing @CRLF from a string variable.
strMyVariable = "abc" : @CRLF
strMyVariable = StrSub (strMyVariable, 1, StrLen (strMyVariable) - 2)


; Remove one trailing @CRLF from a string variable.
strMyVariable = "abc" : @CRLF
strMyVariable = ItemRemove (-1, ItemRemove (-1, strMyVariable, @LF), @CR)



; Remove leading multiple @CRLF's from a string variable.
strMyVariable = @CRLF : @CRLF : "abc"
strText = strMyVariable
intPos = 1
While intPos == StrIndex (strText, @CRLF, intPos, @FWDSCAN)
   intPos = intPos + 2
EndWhile
strMyVariable = StrSub (strText, intPos, -1)


; Remove trailing multiple @CRLF's from a string variable.
strMyVariable = "abc" : @CRLF : @CRLF
strText = strMyVariable
intPos = StrLen (strText)
While intPos == 1 + StrIndex (strText, @CRLF, intPos, @BACKSCAN)
   intPos = intPos - 2
EndWhile
strMyVariable = StrSub (strText, 1, intPos)



; Remove leading multiple @CRLF's from a string variable.
strMyVariable = @CRLF : @CRLF : "abc"
strMyVariable = StrReplace (ItemRemove (-1, StrTrim (StrReplace (strMyVariable, @CRLF, @TAB) : @LF), @LF), @TAB, @CRLF)


; Remove trailing multiple @CRLF's from a string variable.
strMyVariable = "abc" : @CRLF : @CRLF
strMyVariable = StrReplace (ItemRemove (1, StrTrim (@LF : StrReplace (strMyVariable, @CRLF, @TAB)), @LF), @TAB, @CRLF)


; Remove leading and trailing multiple @CRLF's from a string variable.
strMyVariable = @CRLF : @CRLF : "abc" : @CRLF : @CRLF
strMyVariable = StrReplace (StrTrim (StrReplace (strMyVariable, @CRLF, @TAB)), @TAB, @CRLF)



; Remove leading empty lines (@CRLF's) from a textfile.
strText = FileGet (strFilename)
intPos = 1
While intPos == StrIndex (strText, @CRLF, intPos, @FWDSCAN)
   intPos = intPos + 2
EndWhile
intBytesWritten = FilePut (strFilename, StrSub (strText, intPos, -1))


; Remove trailing empty lines (@CRLF's) from a textfile.
strText = FileGet (strFilename)
intPos = StrLen (strText)
While intPos == 1 + StrIndex (strText, @CRLF, intPos, @BACKSCAN)
   intPos = intPos - 2
EndWhile
intBytesWritten = FilePut (strFilename, StrSub (strText, 1, intPos))


; Remove leading empty lines (@CRLF's) from a textfile.
intBytesWritten = FilePut (strFilename, StrReplace (ItemRemove (-1, StrTrim (StrReplace (FileGet (strFilename), @CRLF, @TAB) : @LF), @LF), @TAB, @CRLF))


; Remove trailing empty lines (@CRLF's) from a textfile.
intBytesWritten = FilePut (strFilename, StrReplace (ItemRemove (1, StrTrim (@LF : StrReplace (FileGet (strFilename), @CRLF, @TAB)), @LF), @TAB, @CRLF))


; Remove leading and trailing empty lines (@CRLF's) from a textfile.
intBytesWritten = FilePut (strFilename, StrReplace (StrTrim (StrReplace (FileGet (strFilename), @CRLF, @TAB)), @TAB, @CRLF))



; Remove last line (empty or not) from a textfile.
intBytesWritten = FilePut (strFilename, ItemRemove (-1, ItemRemove (-1, FileGet (strFilename), @LF), @CR))

Exit