Read-only archive of the All About Symbian forum (2001–2013) · About this archive

I need faster text file reading

1 replies · 2,352 views · Started 06 March 2004

I want to search a string in a plain ascii text file on 9210 with OPL. the text file has about 5000 lines, so my following code is much too slow:

PROC IOReadASCIIString$😞aHandle%,aExcludeCRLF%)
LOCAL Ret%,String$(KMaxStringLen%),_Buffer&,NextChar$(1)
_Buffer&=ALLOC(1)
IF _Buffer&=0
RETURN ""
ENDIF
DO
Ret%=IOREAD(aHandle%,_Buffer&,1)
IF Ret%>=0
NextChar$=CVUnicode$😞_Buffer&,1)
IF (((NextChar$=CHR$(KLineFeed&😉) OR (NextChar$=CHR$(KCarriageReturn&😉)) AND aExcludeCRLF%)
rem Do nothing
ELSE
String$=String$+NextChar$
ENDIF
ENDIF
UNTIL (NextChar$=CHR$(KLineFeed&😉) OR (Ret%<0)
FREEALLOC _Buffer&
RETURN String$
ENDP

and my loop is:

IOOPEN(h%,"C:\Documents\myfile.txt",$0000)
DO
String$=IOReadASCIIString$😞h%,KTrue%)
PRINT String$
UNTIL loc(String$,search$)>0 or string$=""

How can I make it faster? Searching in a text file was much faster on ER5 Psion.

Hi,

I suggest reading your text file into a buffer because it is not large at all, look at on the dpNote 0018 section of :

http://www.dp.com.my/

Then use the Buffer.opx functions :

BufferFind&:, BufferLocate&:, etc.

The 2nd argument is the lenght (# of chars) of the string, not its size.

Good luck,

Roberto