How to TRIM() cr/lf?

What about TRIM() for removing white space from strings!
Although it is a really handy BUG-ELIMINATOR for *IF* ever a user pastes rich text into your (MS-Access) application, STILL this attachment demonstrates that TRIM only works on outer spaces, not other white space characters like ASCII characters 9, 10, 12, 13. (vbTab, vbLf, Formfeed, vbCr)

' Save this in a VBS file on your desktop for a VISUAL DEMO comparing three string cleaning functions below
Dim someOtherString, someOtherString1, someOtherString2, someOtherString3
someOtherString1 = vbCrLf & vbTab & "Hi Mom!" & int(rnd(100)*5) & vbTab & vbCrLf
someOtherString2 = vbCrLf & vbTab & "Hi Mom!" & int(rnd(100)*5) & vbTab & vbCrLf
someOtherString3 = vbCrLf & vbTab & "Hi Mom!" & int(rnd(100)*5) & vbTab & vbCrLf
msgbox chr(34) & trim(someOtherString1) & chr(34),,"Trim"
msgbox chr(34) & nibble(someOtherString2) & chr(34),,"Nibble"
msgbox chr(34) & chomp(someOtherString3) & chr(34),,"Chomp"
' --------------------
Function chomp(somestring)
if len(somestring) >= 1 then
while (asc(right(somestring,1)) <= 13 )
somestring = left(somestring, len(somestring)-1)
end if
chomp = somestring
End Function
' --------------------
Function nibble(somestring)
if len(somestring) >= 1 then
while (asc(left(somestring,1)) <= 13 )
somestring = right(somestring, len(somestring)-1)
end if
nibble = somestring
End Function


2 thoughts on “How to TRIM() cr/lf?”

  1. It's a pity you don't have a donate button! I'd certainly donate to this superb blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this website with my Facebook group. Talk soon!

  2. Howdy just wanted to give you a quick heads up and let you know a few of the images aren't loading correctly. I'm not sure why but I think its a linking issue. I've tried it in two different browsers and both show the same results.

Comments are closed.