MemoryBlock.CString
From Xojo Documentation
Method
Returns a String. Offset is in bytes from the beginning of the MemoryBlock.
Notes
A CString is a sequence of non-zero bytes followed by a terminating Chr(0) that marks the end of the CString. MemoryBlock.CString returns a String consisting of the non-zero bytes beginning at Offset and ending before the terminating 0 byte.
Sample Code
When setting MemoryBlock.CString, one extra byte of space is needed for the CString terminator. Thus, for example, when setting the CString property of a MemoryBlock to a 15-byte string, 16 bytes of the MemoryBlock are actually set.
This example shows how to add the terminating null if the string doesn't already have it. It uses the string that was constructed in the Byte example.
Var m As New MemoryBlock(14)
m.Byte(0) = 12 // length byte for a PString
m.Byte(1) = 72
m.Byte(2) = 101
m.Byte(3) = 108
m.Byte(4) = 108
m.Byte(5) = 111
m.Byte(6) = 32
m.Byte(7) = 87
m.Byte(8) = 111
m.Byte(9) = 114
m.Byte(10) = 108
m.Byte(11) = 100
m.Byte(12) = 33
MessageBox(m.PString(0))
// To read the string using CString, set the terminating byte before the call.
m.Byte(13) = 0
MessageBox(m.CString(1)) // Skip first value which is the length for the String
m.Byte(0) = 12 // length byte for a PString
m.Byte(1) = 72
m.Byte(2) = 101
m.Byte(3) = 108
m.Byte(4) = 108
m.Byte(5) = 111
m.Byte(6) = 32
m.Byte(7) = 87
m.Byte(8) = 111
m.Byte(9) = 114
m.Byte(10) = 108
m.Byte(11) = 100
m.Byte(12) = 33
MessageBox(m.PString(0))
// To read the string using CString, set the terminating byte before the call.
m.Byte(13) = 0
MessageBox(m.CString(1)) // Skip first value which is the length for the String