Hello from 2021 !
jmcihinney, I have just created an account for the sole purpose of answering your question.
I am currently at work, half an hour after the end of my shift and I wanted a quick answer
on how to quickly trim any and all vbcrlf s at the end or beginning of my string
I have search google for "VBA trim trailing vbcrlf" and this forum thread is the second result.
The elegant answer you have given involving myString.TrimEnd, does not work because, yes, this is a vb.net answer.
Apparently no one asked this question before for VBA or maybe it is in the catacombs on the second page of google's search results.
So, I'm pretty happy that vb1der has posted a VBA answer.
And I will now test this answer
From VB immediate console
And I made a function out of it tooCode:bSTR = "mystringblabla" & vbcrlf & vbcrlf & vbclf print bSTR mystringblabla While Asc(Right(bSTR, 1)) = 10 Or Asc(Right(bSTR, 1)) = 13 : bSTR = Left(bSTR, Len(bSTR) - 1) : Wend print bSTR mystringblabla marker------------------marker
Code:Function TrimEnd(ByVal myString As String, myTrim As String) As String If myString = "" Or myTrim = "" Then TrimEnd = myString: Exit Function While Right(myString, Len(myTrim)) = myTrim: myString = Left(myString, Len(myString) - Len(myTrim)): Wend: TrimEnd = myString End Function




Reply With Quote