RosettaCodeData/Task/Read-a-file-line-by-line/OxygenBasic/read-a-file-line-by-line.basic
2023-07-01 13:44:08 -04:00

36 lines
570 B
Text

function getline(string s, int *i) as string
int sl=i, el=i
byte b at strptr(s)
do
select b[el]
case 0
i=el+1 : exit do
case 10 'lf
i=el+1 : exit do
case 13 'cr
i=el+1
if b[i]=10 then i++ 'crlf
exit do
end select
el++
loop
return mid(s,sl,el-sl)
end function
'read all file lines
'===================
string s=getfile "t.txt"
int le=len(s)
int i=1
int c=0
string wr
if le=0 then goto done
do
wr = getline(s,i)
'print wr
c++
if i>le then exit do
end do
done:
print "Line count " c