Jump to content

Read a file line by line: Difference between revisions

(Add CLU)
Line 2,652:
<lang Oforth>: readFile(fileName)
| line | File new(fileName) forEach: line [ line println ] ;</lang>
 
=={{header|OxygenBasic}}==
The core function '''GetFile''' reads the whole file:
<lang oxygenbasic>
function getline(string s, sys *i, *el) as string
sys e
e=instr i,s,chr(el)
if e=0 then
el=10
e=instr i,s,chr(el) 'files not using chr 13
end if
if e=0 then e=len s
e++
if el=13 then
if asc(s,e)=10 then e++ 'crlf
end if
function = mid s,i,e-i
i=e
end function
 
'=====
'TEST:
'=====
 
s=getfile "t.txt"
i=1
wr=""
c=0
el=13
do
wr = getline s,i,el
if wr="" then exit do
'print wr
c++
end do
print "Line count " c
</lang>
 
=={{header|PARI/GP}}==
54

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.