MemoryBlock.CString

From Real Software Documentation

Jump to: navigation, search
Method
MemoryBlock.CString ( Offset as Integer ) As String

Returns a String. Offset is in bytes from the beginning of the MemoryBlock.

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.


Examples

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.

dim m as new MemoryBlock(16)
m.CString(0) = "Ecce quam bonum"



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.

Dim 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
MsgBox m.pstring(0)

//To read the string using CString, set the terminating byte before the call.
m.byte(13)=0
MsgBox m.CString(1)
Personal tools