
'=============
'LINE SPLITTER
'=============

indexbase 1
string lines[100000] 'static lines array
string cr             '
int b,i,j            '


'data:
'=====

'txt=getfile "s.txt"

'txt=nuls 100000
'sendMessage richedit1,WM_GETTEXT,100000, strptr txt
'
string txt="11
22
33
44
55
66

77"

'initial
'=======
'
'
b=1  'start of line
i=0  'lines array index
j=1  'char index
'
'
'splitter loop
'=============
'
do
  select asc(txt,j)
  case 0
    if j-b>0 then
      i++
      lines[i]=mid(txt,b,j-b) 'FINAL LINE
    end if
    exit do
  case 10 'LF TERMINATED LINES
    i++
    lines[i]=mid(txt,b,j-b)
    b=j+1
  case 13 'CR AND CRLF TERMINATED LINES
    i++
    lines[i]=mid(txt,b,j-b)
    if asc(txt,j+1)=10 then j++ 'SKIP LF
    b=j+1
  end select
  j++    
end do


cr=chr(13)+chr(10)
print "Lines:  " i cr +
      "Line 5: " lines[5] + cr +
      "Last:   " lines[i]
