Separating Substrings in Streams

BlitzMax Forums/BlitzMax Beginners Area/Separating Substrings in Streams

KrayzBlu(Posted 2005) [#1]
Hi, I'm trying to add in a code to my game which will read a line out of a text file. I know how to get it to read OK, but what if I have multiple elements on the same line, separated by commas, and I want BM to put each one into an array?

I've tried using the Find and Replace meathods but I'm getting nowhere :/

Thanks


bradford6(Posted 2005) [#2]
1 Use LUA to read the lnes
2. push for Python mod and use regular expressions to read the line and create array/list
3.
create a parsing language to extract CSV values.


Bot Builder(Posted 2005) [#3]
http://www.blitzbasic.com/codearcs/codearcs.php?cat=9

Take your pick of string splitting functions. IMHO, reg exps are overused, difficult to understand, and slower than hardcoding.


Booticus(Posted 2005) [#4]
http://www.blitzmax.com/Community/posts.php?topic=42540&hl=stringutils

Rob K made these functions, I find them handy and might be what you're looking for.


klepto2(Posted 2005) [#5]
http://www.blitzbasic.com/codearcs/codearcs.php?code=1399

Try the 'Return_Strip' Function.
It divides the string at the given AscII code and returns it to an Array.


KrayzBlu(Posted 2005) [#6]
Hmmm...
Thanks guys, but I think I found out how to do it with the ".Find" meathod to give me the two indexes of the commas, and then subtracted them to get the index length of the numbers.

Does anyone know how to use the "ReadString" function? All its doing for me right now is crashing my program...

And yes, I'm a newb :) Other ways seem a bit too complicated for my level.

Thnx


Perturbatio(Posted 2005) [#7]
The readstring function requires that you know the length of the string prior to reading it.
If you are reading from a stream you need to:
make a note of the current stream location (StartLoc)
read each character in the stream until you encounter your delimiter.
make a note of the current stream location (EndLoc)
use SeekPos to reset the stream back to StartLoc
use readstring to read in a string of length (EndLoc - StartLoc)


KrayzBlu(Posted 2005) [#8]
Yeah .... thats what I was talking about in my last post....

I meant the specifics of the function, an example maybe. I have that all set up, but all it does is crash my program...