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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line Feed and Carriage Return

Status
Not open for further replies.

lebronletchev

Programmer
Oct 17, 2007
17
ES
Hi,

Could I to delete the actual the Line Feed and Carriage Return in a .txt file and change them by other codes?

Thanks

Lebron
 
Yes,
Check STRTRAN() function in HELP

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
LPARAMETERS pcString
pcString = IIF(VARTYPE(pcString) <> 'C', '', pcString)
pcString = STRTRAN(pcString, CHR(10), "")
pcString = STRTRAN(pcString, CHR(13), "")
RETURN pcString

David W. Grewe Dave
 
David, there is better way :) if you want to change these chars one by one:
(based on your function);
Code:
LPARAMETERS pcString
pcString = IIF(VARTYPE(pcString) <> 'C', '', pcString)
pcString = CHRTRAN(pcString, CHR(13)+CHR(10), "")
RETURN  pcString

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
I have testes this script, but don´t works fine:

LOCAL x
x= FILETOSTR("lazarillo.TXT")
scan
x= STRTRAN(x,CHR(13), "#")
endscan

LOCAL x
x= FILETOSTR("lazarillo.TXT")
scan
x= STRTRAN(x,CHR(13), "#")
endscan

Lebron
 
Lebron,

Your code should convert the CRs to #s, but it won't touch the LFs.

But I don't know why you have a SCAN and ENDSCAN in there. That will just cause the code to be repeated for every record in the current table. Is that what you want? Why?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Check:
Code:
x= FILETOSTR("lazarillo.TXT")   
x= CHRTRAN(x,CHR(13)+CHR(10), "##")

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Borislav
What happens if there is a Line Feed with no Carriage Return in the file or Visa-Versa ???


David W. Grewe Dave
 
Mike Lewis,
==========


I have some .txt files which have CHR(13) at the end of each line when in reality this code would must appear at the end of each paragraph.

I want convert all chr(13) and chr(10), for example, for "#" and "$" respectively and after doing this task (which would clean the .txt file from chr(13) and chr(10))
remark the text exactly where I want to get the chr(13) and chr(10).

I hope to be clear.

Thank you for you interest.

Best

lebron


 
Lebron,

I understand that, but that has got nothing to do with SCAN / ENDSCAN. Those commands loop through a table, not a text file.

Please read Borislav's replies. The code he gave you in his most recent message will do exactly what you want, as far as I can see.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Dave,

What happens if there is a Line Feed with no Carriage Return in the file or Visa-Versa ???

Borislav's code will handle that. CHRTRAN() works on the individual characters, unlike STRTRAN() which treats the string as a whole.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Perfect!

Thank you very much. It is a simple code, but with a large utility!

Lebron
 
Interesting... in last step it don´t reconvert "##" to CHR(13)+CHR(10). Strange?

Lebron
 
What is you last step?
What you try to do>
Why you need to convert CRLF to something else?

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Good morning Mr. Borissov!

Yes.

I did several steps and finally I did

CHRTRAN(x,"##", CHR(13)+CHR(10))

Thus I open the text in MSWORD and nothing! Where are the
Carriage Return and Line Feed?

As I explain before some text files - in any format - have different CR and LF. The bad - for me - when I find a text file where each CR & LF are shown at end of EACH LINE! Terrible!

Lebron
 
I am really not sure what you try to do and why.
How text files will have different CR LF? They are all the same CHR(13) and CHR(10). Some of them will have both as end-of-line marker some of them will have only LF as EOL marker, but the chars are always the same.


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Yes. The chars are the same.

When I say different CR LF I want to say some of them have as end-of-line marker and other have only LF as EOL marker.

AND I want DELETE ALL CR LF as end-of-line marker remaining just the LF as EOL MARKER.

It is just I am trying to do!

A little (hypothetical) example will put a light at my explanation (Evidently we don´t see these markes on the text!!!)

===========================================
The jury said it found the court "has incorporated (CR LF)
into its operating procedures the recommendations" of (CR LF)
two previous grand juries, the Atlanta Bar Association (CR LF)
and an interim citizens committee. "These actions (CR LF)
should serve to protect in fact and in effect the (CR LF)
court's wards from undue costs and its appointed and (CR LF)elected servants from unmeritorious criticisms", (CR LF)
the jury said.

====================================================
I want change for:

The jury said it found the court "has incorporated into its operating procedures the recommendations" of two previous grand juries, the Atlanta Bar Association and an interim citizens committee. (CR LF) "These actions should serve to protect in fact and in effect the court's wards from undue costs and its appointed and elected servants from unmeritorious criticisms", the jury said. (CR LF)

*********************************************

Thanks for your helpful.

lebron
 
Try this:
Code:
#define CRLF CHR(13)+CHR(10)

*** Prepare test file
TEXT TO lcTest NOSHOW
The jury said it found the court "has incorporated
into its operating procedures the recommendations" of
two previous grand juries, the Atlanta Bar Association
and an interim citizens committee.
"These actions should serve to protect in fact and in effect the
court's wards from undue costs and its appointed and
elected servants from unmeritorious criticisms",
the jury said.  
ENDTEXT
STRTOFILE(lcTest,[Test.TXT])



lcFile = FILETOSTR([Test.TXT])
lcNewFile = STRTRAN(lcFile, CRLF, [])
lcNewFile = STRTRAN(lcNewFile, [.], [.]+CRLF)
STRTOFILE(lcNewFile, [NewFile.TXT])
MODI FILE NewFile.TXT


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
I some times open these files with a hex editor, it can be most revealing.

If you do much work like this it is worth getting one -- it will save days of grief. I use a 15 year old copy of Multi Edit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top