reading .txt
BlitzMax Forums/BlitzMax Beginners Area/reading .txt| 
 | ||
| Can I read a .txt until I find something certain (like "<hello>"), then return everything after that until another character (like "*")? | 
| 
 | ||
| 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);
 | 
| 
 | ||
| how could i look for something more than one character long(like <blah> instead of just something that starts with <)? | 
| 
 | ||
| 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. | 
| 
 | ||
| look into using XML. there are 2 good max implementations: LibXML by Brucey and MaxML by John J. | 
| 
 | ||
| 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... ;-) |