Substring (open)

Returns part of a string.

Syntax

// Core function, no LOADLIB necessary

STRING FUNCTION Substring(STRING text, INTEGER start, INTEGER numbytes)

Parameters

STRING text

String to return a part from

INTEGER start

Starting byte position

INTEGER numbytes

Number of bytes to return. When omitted, the portion from start until the end of the string is returned.

Return value

STRING

The requested part of the string

Description

Substring returns the part of string specified by the start and length parameters. If the string after the start position contains less than the requested number of bytes, the whole string after the start position is returned. If the length parameter is omitted, the portion of string beginning at start and ending at the end of the string is returned When manipulating UTF-8 strings it is recommended that you use the function UCSubstring because UTF-8 characters can be made up from more bytes and the result is therefore unpredictable.

Examples

// returns 'bcde'
STRING example1 := Substring("abcdef", 1, 4);

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

// returns '€uro'
STRING example3 := UCSubstring("euro€uro", 4, 4);

// returns an empty string
STRING example4 := Substring("abcdef", 100, 100);

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