Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

CDavis (Programmer) (OP)
26 Jan 10 12:07
I have several expressions on a data entry form that I will combine and save in a memo field.  I want to strip all the CHR(10) and CHR(13) characters from the expressions prior to saving them in the memo field.  Is there a better solution than the following?


DO While RIGHT(THISFORM.comment1.VALUE,1) = CHR(10) ;



Thanks in advance.

Chuck Davis
mmerlinn (Programmer)
26 Jan 10 12:35
One way would be:

comment1 = CHRTRAN(comment1, CHR(13) + CHR(10), "")

This would remove ALL line feeds and returns regardless of position.


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond


CDavis (Programmer) (OP)
26 Jan 10 13:39
Thanks mmerlinn,

I did consider using CHRTRAN() -- I should have noted that I want to retain any CR/LF except those that are at the very end of the data.  Ultimately I will re-insert a set number of CR/LF for formatting purposes.  Some end-users hit the enter key several times at the end of their data entry and I want to strip those out.

The code I've written is working -- but I wanted to see if there were any other alternatives.

SnyAc (Programmer)
26 Jan 10 13:56
try this...


with thisform.comment1
  .value = rtrim(.value)
  .value = iif(right(.value,2)=chr(13)+chr(10), left(.value, len(.value)-2), .value)

Andy Snyder
SnyAc Software Services
Hyperware Inc. a division of AmTech Software

SnyAc (Programmer)
26 Jan 10 14:03
actually if you are dealing with an unknown number of additional CRLF's your original code is probably the best solution...

Andy Snyder
SnyAc Software Services
Hyperware Inc. a division of AmTech Software

CDavis (Programmer) (OP)
26 Jan 10 16:04
Thanks Andy,

I always like to look at alternatives and based on your idea, I may test for CHR(13) + CHR(10) together and cut the number of passes through the DO WHILE loop in half.

-- Chuck Davis
Helpful Member!  TamarGranor (Programmer)
26 Jan 10 16:11
If you're in VFP 9, take a look at the optional cParseChar parameter for TRIM() and ALLTRIM().

jrbbldr (Programmer)
26 Jan 10 16:25
"I may test for CHR(13) + CHR(10)"

There are a wide variety of ways to do what you are wanting.
One way might be as follows:


nOccurs = OCCURS(CHR(13) + CHR(10), comment1)
IF nOccurs > 0
   IF RIGHT(comment1,2) = CHR(13) + CHR(10)
      nLoc = RAT(CHR(13) + CHR(10),comment1)
      comment1 = LEFT(comment1,(nLoc-1))

Good Luck,
SnyAc (Programmer)
26 Jan 10 16:48
after a little idle thought...


with thisform.comment1
  lnTmp = alines(laTmp, .value)
  for lnI = lnTmp to 1 step -1
    if !empty(laTmp(lnI)) && find the last populated line
  lcTmp = laTmp[1]
  for lnTmp = 2 to lnI
    lcTmp = lcTmp + chr(13)+chr(10) + laTmp[lnTmp]
  .value = lcTmp

Andy Snyder
SnyAc Software Services
Hyperware Inc. a division of AmTech Software

alan92rttt (Programmer)
26 Jan 10 17:38
IF your in VFP 9 Tamar's solution is perfect


lcString=[test test test]+CHR(13)+CHR(10)
lcString=lcStrng+[test test test]+CHR(13)+CHR(10)
lcString=lcString+[test test test]+CHR(13)+CHR(10)
? [<start>]+RTRIM(lcString)+[<end>]
? [<start>]+RTRIM(lcString,CHR(13),CHR(10))+[<end>]

If your not in 9 this could strip all trailing CHR(13)+CHR(10)'s


CDavis (Programmer) (OP)
26 Jan 10 18:01
Thanks to everyone for posting your thoughts.  As I suspected there are many ways to accomplish a task.  I'm using VFP 9 so Tamar's suggestion seemed the most elegant and accomplished the task in the fewest lines of code:


THISFORM.comment1.VALUE = RTRIM(THISFORM.comment1.VALUE ,1 , CHR(13), CHR(10))

-- Chuck

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close