ZTrim Function

Purpose

Copies a string until the first null-byte.

Syntax

$ = ZTrim[$](a$)

a$:sexp

Description

ZTrim(a$) scans the string for the first occurrence of a null-byte, a Chr(0) or #0. It then returns the contents up to the null-byte. When the string doesn't contain a null-byte the entire string is returned.

The function a$ = ZTrim(a$) is similar with

If InStr(a$, #0) Then a$ = Left(a$, InStr(a$, #0))

and

a$ = Char{V:a$}

ZTrim most useful with Windows API functions that return strings in a fixed length buffer.

Example

Local buf As String*32

Local iLen As Int = 32

~GetComputerName(V:buf, V:iLen)

buf = ZTrim(buf)

'or:

'buf = Left(buf, iLen)

Message buf, iLen

Remarks

See Also

Char{}, LTrim(), RTrim(), Trim()

{Created by Sjouke Hamstra; Last updated: 25/10/2014 by James Gaite}