Manage Learn to apply best practices and optimize your operations.

Trim returns and line feeds

This tip is a LotusScript function that trims the returns and line feeds from a string.

View member feedback to this tip.

I had to create this function because we have address fields set to OS Style and they can display multiple lines. Users entered addresses with carriage returns to change to a new line and the fields often ended up with extra carriage returns. We have code that traps changes in the address fields. When comparing the previous and actual addresses, if one contained extra returns and nothing else was changed, the values were considered unequal with the trim function. I created this TrimReturns function so addresses in which only trailing returns are the difference would actually be compared as equals.

The following is a LotusScript function that trims the returns and line feeds from a string.

Function TrimReturns(inputString 
As String) As String
 'This function removes the trailing 
carriage returns and line feeds from a string 
and returns the input string without these 
 'Code by Benoit Dubuc
 Dim position As Integer
 Dim lastChar As String
 position = Len(inputString)
 lastChar = Right(inputString, 1)
 While Asc(lastChar) = 10 
Or Asc(lastChar) = 13
  position = position -1
  lastchar = Right ( Left(inputstring,
 position), 1)
 TrimReturns = Left(inputString, 
End Function


Doesn't the LotusScript FullTrim function accomplish the same thing?

-- Joseph S.


No, the fullTrim function leaves the trailing carriage returns. It only trims spaces. I think FullTrim was mainly built to trim arrays from empty entries.

-- Benoit Dubuc


You may already know this but in R6, you can do this natively with the Replace function:

Dim strText As String

strText$ = "My name: " & Chr(13) 
& "Dallas G." & Chr(13)
strText$ = strText$ & Chr(13) & 
"My email: " & Chr(13) &
companyname_dot_com" & Chr(13)
strText$ = strText$ & Chr(13) & 
"My number: " & Chr(13) & "(806)555-6251"

Msgbox strText$, , "DEBUG . . ."

strText$ = Replace(strText$, Chr(13), "-")
Msgbox strText$, , "DEBUG . . ."
-- Dallas G.


This is a great tip. I was needing to remove only trailing carriage returns and the Replace function removes all of the Carriage returns. Benoit's function accomplished exactly what I needed with very minimal code.

-- Mark H.

Do you have comments of your own? Let us know.

Dig Deeper on LotusScript



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury