The code below is modified to run stand-alone, the app Procedure actually uses some global vars for expedience and performs a check to first decide if the file even needs to be processed.
Code: Select all
EnableExplicit
#FileIO = 0
Define iFound.i, iFormat.i, iReadOk.i = #False
Define qFileLen.q, sEol.s
Define *TextBuff
If ReadFile(#FileIO, "C:\MyTextFile.txt")
iFormat = ReadStringFormat(#FileIO)
qFileLen = Lof(#FileIO)
If(qFileLen > 0)
*TextBuff = AllocateMemory(qFileLen)
ReadData(#FileIO, *TextBuff, qFileLen)
CloseFile(#FileIO)
;Determine the end of line string
iFound = FindString(PeekS(*TextBuff, qFileLen, iFormat), #CRLF$, 1, #PB_String_NoCase)
If(iFound > 0)
sEol = "#CRLF$"
Else
iFound = FindString(PeekS(*TextBuff, qFileLen, iFormat), #CR$, 1, #PB_String_NoCase)
If(iFound > 0)
sEol = "#CR$"
Else
sEol = "#LF$"
EndIf
EndIf
Debug sEol
EndIf
Else
Debug "ReadFile failed"
EndIf
End
Now the snag is the "Determine the end of line string" code. If the Eol is not #CRLF$ (Windows OS), a second search is performed. Is there a more efficient way to find the Eol used?