reading .txt

BlitzMax Forums/BlitzMax Beginners Area/reading .txt

drnmr(Posted 2006) [#1]
Can I read a .txt until I find something certain (like "<hello>"),
then return everything after that until another character (like
"*")?


Jim Teeuwen(Posted 2006) [#2]
this code is untested and I wrote it off the top of my hat, so you may see some typo's, but it should give an idea of how to make a simple file-parser.

it's very basic and can use some optimizing.

the > character is used to start reading data, and * is used to stop reading data.

local fs:TStream = ReadFile("blah.txt");
local buffer:string = "";
local reading:byte = False;

while( not fs.Eof() )
   local c:byte = readbyte(fs);

   select( c )
     case Asc(">")
       reading = True;

     case Asc("*")
       reading = False;
       Exit;

     default
       if( reading ) then
          buffer :+ Chr(c);
       end if
   end select
wend

closefile(fs);

Print(buffer);



drnmr(Posted 2006) [#3]
how could i look for something more than one character long(like <blah> instead of just something that starts with <)?


kfprimm(Posted 2006) [#4]
http://www.blitzbasic.com/codearcs/codearcs.php?code=1416 its BlitzPlus and may look hard to understand but the parsing does what you need it to do.


bradford6(Posted 2006) [#5]
look into using XML. there are 2 good max implementations:
LibXML by Brucey and MaxML by John J.


Brucey(Posted 2006) [#6]
you can syncmods for the libxml module (on windows and linux) :
syncmods -u your_user_name -p your_password bah.libxml

Handles xml parsing in ways you haven't event thought of yet... ;-)