Left (open)

Returns the left part of a string.

Syntax

// Core function, no LOADLIB necessary

STRING FUNCTION Left(STRING text, INTEGER numbytes)

Parameters

STRING text

String to return a part from

INTEGER numbytes

Number of bytes to return

Return value

STRING

The requested part of the string

Description

Left returns the first 'n' bytes from a string. If a string contains less than the requested number of bytes, the entire string is returned. When manipulating UTF-8 strings it is recommended that you use the function UCLeft because UTF-8 characters can be made up from more bytes and the result is therefore unpredictable.

Examples

// returns 'ab'
STRING example1 := Left("abcdef", 2);

// returns '€u'
STRING example2 := Left("€uro", 4);

// returns '€uro'
STRING example3 := UCLeft("€uro", 4)

// returns the entire string, e.g 'abcdef'
STRING example4 := Left("abcdef", 100);

// returns an empty string
STRING example5 := Left("abcdef", -10);