Getting strings from a file using ReadString()?
BlitzMax Forums/BlitzMax Beginners Area/Getting strings from a file using ReadString()?
| ||
How do I do this without knowing the length of the string I am reading? |
| ||
ReadLine. |
| ||
Method ReadLine$() Description: Read a line of text from the stream Information: Bytes are read from the stream until a newline character (ascii code 10) or null character (ascii code 0) is read, or end of file is detected. Carriage return characters (ascii code 13) are silently ignored. The bytes read are returned in the form of a string, excluding any terminating newline or null character. |
| ||
You can use ReadLine (as others before me have said) or make two custom functions: one that writes the length of the string as an integer, then the string; and another function that reads the length of the string, and then the string (based on the length read). |
| ||
An example of the custom functions Plash described:Function BBReadString:String(stream:TStream) Local size:Int=ReadInt(stream) Return ReadString(stream,size) EndFunction Function BBWriteString(stream:TStream,t:String) Local size:Int=t.length WriteInt(stream,size) WriteString(stream,t) EndFunction This is the way BlitzPlus, Blitz3D, etc. does it. |