substr

Syntax

substr(X, offset, [length])

Arguments

X is a string scalar/vector.

offset is a nonnegative integer.

length is a positive integer.

Details

Return a substring of X with the specified starting position (offset) and length (length). The first character of X corresponds to position 0. If length exceeds the length of X, stop at the end of X.

If length is not specified, return a substring of X from the specified starting position (offset) to the end of X.

Examples

$ substr("This is a test", 0, 4);
This

$ substr("This is a test", 5, 2);
is

$ substr("This is a test", 5);
is a test

$ substr("This is a test", 8, 100);
a test