Text File EOL Processing

Started by KeithW, September 08, 2025, 02:18:14 PM

Previous topic - Next topic

KeithW

I am not sure what else to use off hand, the following code was an attempt to determine what kind of source OS generated the text file...  for MAC EOL is a CR, *nix system LF and DOS/Windows CRLF but in this code the LF is always gobbled so it appears to be a MAC based text file even though it was generated on Windows. What else can I use to properly determine EOLs correctly.

   DataLine = FileGet(fileToRead)
   Message("DataLine is", DataLine)
   EOLCHK = strsub(Dataline,(strlen(dataline)-2),2)
   Message("*EOLCHK",">...":ChrStringToHex(EOLCHK):"...<")
   if (strsub(EOLCHK,2,1) == @LF && StrSub(EOLCHK,1,1) == @CR) then Message("DOS/WIN EOL"," CR/LF ")
   if (strsub(EOLCHK,2,1) == @LF && StrSub(EOLCHK,1,1) != @CR) then Message("*NIX EOL", "Just a LF")
   if (strsub(EOLCHK,2,1) == @CR && StrSub(EOLCHK,1,1) != @CR) then Message("MAC EOL","Just a CR")

Regards,
Keith

td

The line EOLCHK = strsub(Dataline,(strlen(dataline)-2),2) should be EOLCHK = strsub(Dataline,(strlen(dataline)-1),2).
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

KeithW

Duh, sorry, I should have caught that...


T H A N X !!

SMF spam blocked by CleanTalk