Click or drag to resize

Mem2String Function

Extract a substring of a certain size from the left of a buffer.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.10
Syntax
 FUNCTION Mem2String(
	ptrSource AS IntPtr,
	dwCount AS DWORD
) AS STRING
View Source

Parameters

ptrSource
Type: IntPtr
Pointer to the buffer from which to extract the substring.
dwCount
Type: UInt32
The number of bytes, from the left, to extract from <ptrSource>.

Return Value

Type: String
A substring of the specified number of bytes.
Remarks
Tip Tip
Contrary to normal PSZs, strings are not static and may be collected by the garbage collector.  Therefore, if you supply a string as an argument to a function, like Mem2String, which directly or indirectly allocates dynamic memory, you may run into trouble.  For example, in Mem2String(Time(), 5), Time() may cause problems.  But Mem2String("hi there", 5) will not cause problems since literal strings are not collected.
Examples
This example uses Mem2String() to get the three leftmost characters of a PSZ:
X#
LOCAL pszSource AS PSZ
pszSource := "ABCDEF"
? Mem2String(pszSource, 3)                        // ABC
See Also