I have the following program:
Code: Select all
Option Explicit
'declare some string variables
Dim myDynaString as String
Dim myFixedString as String * 20
Dim myZString as ZString * 30
Dim myWString as WString * 30
'add some data
myDynaString = "Hello World From FreeBasic!"
myFixedString = "Hello World!"
myZString = "Hello World From FreeBasic!"
myWString = "Hello World From FreeBasic!"
'print out the lengths of strings
Print "Length of Dynamic String is";Len(myDynaString);" byte(s)."
Print "Length of Fixed String";Len(myFixedString);" byte(s)."
Print "Length of ZString is";Len(myZString);" byte(s)."
Print "Length of WString is";Len(myWString);" byte(s)."
Print
'print out the variable size
Print "Size of Dynamic String is";SizeOf(myDynaString);" byte(s)."
Print "Size of Fixed String";SizeOf(myFixedString);" byte(s)."
Print "Size of ZString is";SizeOf(myZString);" byte(s)."
Print "Size of WString is";SizeOf(myWString);" byte(s)."
'wait for keypress
Sleep
End
Code: Select all
Length of Dynamic String is 27 byte(s).
Length of Fixed String 20 byte(s).
Length of ZString is 27 byte(s).
Length of WString is 27 byte(s).
Size of Dynamic String is 12 byte(s).
Size of Fixed String 21 byte(s).
Size of ZString is 30 byte(s).
Size of WString is 60 byte(s).
1) Len returns the length of the string data, sizeof returns the size of the variable.
2) The size (using sizeof) for the dynamic string (12) is the length of the string descriptor.
3) The size for the fixed string (21) includes the terminating null byte.
4) If you explicitly declare a size for the Z and WString you don't need to add the terminating null when assigning a value.
As an aside, what is contained in the string descriptor for dynamic strings? I don't want to mess with it, just provide a general idea of the descriptor for the book I am working on.
Thanks!