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 
characters
 '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)
 Wend
 
 TrimReturns = Left(inputString, 
position)
End Function

MEMBER FEEDBACK TO THIS TIP

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) &
"dallasg_at_
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.

This was first published in September 2003

Dig deeper on LotusScript

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close