Home > Language Reference > System Functions > PeekString$

PeekString$

The PeekString$ function retrieves a value of string type from memory.

Usage

Used in conjunction with External function.

Syntax

var$ = PeekString$(<address> [, Unicode])

Parameters

<address>. unsigned variable only. Memory is read starting at this address until end of string character (binary zero) is found. The unsigned variable must be declared at the beginning of the script using Dim function.

Unicode. optional keyword. If specified, Unicode encoding is used for the return value.

Return value

var$, string. If the function fails, script execution stops and no error handling is possible.

See also

PokeString
PeekInteger
PokeInteger

Examples

message$=PeekString$(address_string)


'Script returning the Windows installation folder
'Memory address
dim pointer as unsigned
'Memory allocation
pointer=allocate(64)
'Prepare a variable for the return value
wdir$=" "
'Write the blank string to memory
ret=PokeString(pointer,wdir$,0)
'In Win32, an A must be added to functions returning an ASCII string
a=External("kernel32","GetWindowsDirectoryA",pointer,64)
'Read the string at the given memory address
var$=peekString$(pointer)
msgbox(var$)



'Script returning the Windows installation folder for Asian Windows (Unicode encoding)
'Memory address
dim pointer as unsigned
'Memory allocation
pointer=allocate(64)
'Prepare a variable for the return value
wdir$=" "
'Write the blank string to memory
ret=PokeString(pointer,wdir$,0)
'In Win32, an W must be added to functions returning a Unicode string
a=External("kernel32","GetWindowsDirectoryW",pointer,64)
'Read the string at the given memory address
var$=peekString$(pointer,Unicode)
msgbox(var$)