I want to Remove the Line Break from the string if my string Ends with Line Break.
Sub linebreak(myString)
If Len(myString) <> 0 Then
If Rig
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*$".