No one has ever suggested a RegExp solution. So here is one:
Function TrimTrailingLineBreak(pText)
Dim oRE: Set oRE = New RegExp: oRE.Global = True
oRE.Pattern = "(.*?)(\n|(\r\n)){1}$"
TrimTrailingLineBreak = oRE.Replace(pText, "$1")
End Function
It captures and returns everything up until a single ({1}
) trailing new line (\n
), or carriage return & new line (\r\n
), at the end of the text ($
).
To remove all trailing line breaks change {1}
to *
.
And to remove all trailing whitespace (including line breaks) use oRE.Pattern = "(.*?)\s*$"
.