string length

BlitzMax Forums/BlitzMax Beginners Area/string length

DREAM(Posted 2008) [#1]
is there anyway of reading a string in without knowing how long it is, say if its a null terminated string

levelsetname=ReadString$(levdat,5)

this reads in 5 characters


does the readline$ read in all of A NULL terminated string...


JazzieB(Posted 2008) [#2]
I always use WriteLine/ReadLine for strings, as it's a lot easier than having to know in advance how long a string is, as you do with ReadString.


GfK(Posted 2008) [#3]
Assuming you've written your data sequentially, you could write a byte/short/int before the string, which tells you how long the string actually is.


Grey Alien(Posted 2008) [#4]
If you use WriteStream and ReadStream you have to store a byte before the string.


DREAM(Posted 2008) [#5]
what i was actually trying to do was read a file i hadn't created its a level file for another(somebody else's game), so all i knew was that it contained null terminated strings in 'c' terms the language. so if you dont know how long the string is because you didnt make it, i would have to use readline, also that then begs if i have to then save this file back out when i have modified it, when blitzmax writes say a writeline, is this classed as a null terminated string to be compatible with the previous one read in?


DREAM(Posted 2008) [#6]
oh the other thing with strings each character in a string is 8 bytes is that right, and with null terminated charachters at the end is that one character or 8 bytes anyone know.....?


REDi(Posted 2008) [#7]
No each character is one byte.

Here is a simple example of how you could handle this sort of thing...