Help with reading strings from files
BlitzMax Forums/BlitzMax Beginners Area/Help with reading strings from files
| ||
I've been trying to learn how reading strings from files works, and I ran into a problem. With ReadString I have to tell it how long the string is. With ReadLine I don't have to do that, but it just grabs everything and stuffs it all in the same variable. So I'm looking for a good way to get independent strings out of files. I did find this here , but I couldn't get any of the two examples working. I know I could just put a Int between the strings telling how long they are, and then use ReadString. But that just seems messy and unnecessary. Thanks in advance! |
| ||
Are these strings previously written with BlitzMAX? if so, just add a newline ("~n") at the end, or use WriteLine instead of WriteString, then ReadLine will work properly.SuperStrict Local out:TStream = WriteStream("tempfile.txt") WriteLine out,"One" WriteLine out,"two" WriteLine out,"Three" CloseStream out Local in:TStream = ReadStream("tempfile.txt") While Not Eof(in) Local Line:String = ReadLine(in) Print Line Wend CloseStream in |
| ||
Thank you Tom for the help! The example code was very helpful to me. :-) I do have one question though. What is the difference between WriteStream and WriteFile? I've never seen WriteStream before. Well thanks again Tom. =) |
| ||
What is the difference between WriteStream and WriteFile? I think they are identical. A stream is a more general thing. It could be a traditional file. But it might also be a BlitzMax bank, or even something on a network, like a database for game scores. So you might expect WriteFile to be like WriteStream restricted to files. But I think it is exactly the same and is included as a convenience for people who are already familiar with WriteFile from earlier Blitz languages. |
| ||
Okay. Thanks! =) |