Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strip CR/LF from end of expression. 1

Status
Not open for further replies.

CDavis

Programmer
May 5, 2000
155
US
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?

Code:
DO While RIGHT(THISFORM.comment1.VALUE,1) = CHR(10) ;
OR RIGHT(THISFORM.comment1.VALUE,1) = CHR(13)

THISFORM.comment1.VALUE =;  SUBSTR(THISFORM.comment1.VALUE,1,LEN(THISFORM.comment1.VALUE) -1)

ENDDO

Thanks in advance.

Chuck Davis
 
One way would be:

[tt][blue]
comment1 = CHRTRAN(comment1, CHR(13) + CHR(10), "")
[/blue]
[/tt]

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

mmerlinn


"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
 
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.

 
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
 
If you're in VFP 9, take a look at the optional cParseChar parameter for TRIM() and ALLTRIM().

Tamar
 
"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:

Code:
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))
   ENDIF
ENDIF

Good Luck,
JRB-Bldr
 
after a little idle thought...

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

Andy Snyder
SnyAc Software Services Hyperware Inc. a division of AmTech Software
 
IF your in VFP 9 Tamar's solution is perfect

Code:
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)
lcString=lcString+CHR(13)+CHR(10)
lcString=lcString+CHR(13)+CHR(10)
lcString=lcString+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

Code:
lcS2=RTRIM(STRTRAN(lcString,CHR(13)+CHR(10)+CHR(13)+CHR(10),[]))
lcString=IIF(RIGHT(lcS2,2)=CHR(13)+CHR(10),SUBSTR(lcs2,1,LEN(lcs2-2),lcs2)
 
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:

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

-- Chuck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top