Finding cr Character in Lines read from a file???

Mark Schonewille m.schonewille at economy-x-talk.com
Fri Jun 29 11:33:19 EDT 2007


Hi Dave,

Probably, your file contains actual returns (ASCII 13), which are  
translated to linefeeds by Revolution, if the file is read as text.  
To make it "easy", linefeed, lf, cr and return all return ASCII 10  
rather than ASCII 13. Only crlf contains both a real linefeed and a  
real return character. If you want to use an actual carriage return,  
use numtochar(13).

If you are parsing lines, you might never get at the linefeed. Syntax  
like

put line 1 of myVar

will never include the line delimiter. It is not considered part of  
the line.

There are two things you can do. Either read the file as binary data  
and search for ASCII 13.

open file myFile for binary read
read from file myFile until EOF
put it into myVar
close file myFile
-- now do whatever you want to do with it
replace numToChar(13) with "%" in myVar

or read the file as text and handle the linefeeds

open file myFile for read
read from file myFile until EOF
put it into myVar
close file myFile
-- now do whatever you want to do with it
replace cr with "%" in myVar

Best regards,

Mark Schonewille

--

Economy-x-Talk Consulting and Software Engineering
http://economy-x-talk.com
http;//www.salery.com

Quickly extract data from your HyperCard stacks with DIFfersifier.  
http://differsifier.economy-x-talk.com


Op 29-jun-2007, om 17:06 heeft Dave het volgende geschreven:

> Hi,
>
> I have a file that has "cr" (0x0D) terminators on each line.
>
> If I have the line in "myLine" and do this:
>
> repeat with myIndex = 1 to the length of  myLine
> if char myIndex of myLine = cr then
> --do something at end of line
> end if
> end repeat
>
> It never finds the cr. I looked in the file and conformed that the  
> lines end in a single cr character.
>
> When I did a charToNum() on cr is returns 0x0A which is a lf!!!!!
>
> What gives? How can I find the real cr is a variable?
>
>
> All the Best
> Dave
>




More information about the use-livecode mailing list