StrGet()

Auto Hotkey

StrGet

Copies a string to or from a memory address, optionally converting to or from a given code page.

OutputVar := StrGet(Address , Length, Encoding = None
Function Example: string := StrGet(stringAddr, 10, "UTF-8")

Parameters

OutputVar

The name of the variable in which to store the read string.

Address

The address at which the string will be written to/read from.

Length

The maximum number of characters to read/write, including the null-terminator if required. See Return Value.

Encoding

The source encoding for StrGet or target encoding for StrPut; for example, "UTF-8", "UTF-16" or "CP936". If Address and Length are not specified, numeric identifiers must be prefixed with "CP". Specify an empty string or "CP0" to use the system default ANSI code page.

Return Value

Invalid parameters cause an empty string to be returned, otherwise returns the requested string after performing any necessary conversion.

Remarks

Note that the return value of StrGet are always in the native encoding of the current executable, whereas Encoding specifies the encoding of the string written to or read from the given Address. If no Encoding is specified, the string is simply copied without any conversion taking place.

If conversion between code pages is necessary, the required buffer size may differ from the size of the source String.

Scripts which are required to be compatible with AutoHotkey Basic can still use StrGet provided that the appropriate script files are installed in a function library. These scripts can be found at the AutoHotkey Community Forum.

Related

Script Compatibility, StrPut, StrPutVar, FileEncoding , VarSetCapacity

Examples

Either Length or Encoding may be specified directly after Address, but in those cases Encoding must be non-numeric:

strA := StrGet(addressA, "cp0")     ; OK
strA := StrGet(addressA, length, 0) ; OK
strA := StrGet(addressA, 0)         ; Error