FEEL

substring

FEEL built-in function · FEEL string functions

substring(string, start position, length?)

Returns the part of the string that starts at start position. Without length, it runs to the end of the string; a negative start position counts backwards from the end.

A negative start position counts from the end: -1 is the last character, -3 the third from last. DMN 1.6 defines substring only for positions inside the string: the start position must be non-zero and within [-length..length], and the length must be at least 1 and must not run past the end. Anything else is outside the function's domain, and the result is null. A fractional start position or length is truncated, as for every integer parameter of a built-in.

Parameters

ParameterTypeDescription
stringstringthe source string
start positionnumber1-based start; negative counts from the end
lengthnumbermaximum characters to return (optional)

Examples

substring("foobar", 3)
substring("foobar", 3, 3)
substring("foobar", -2, 1)

Edge cases and null handling

substring("foobar", -3)

Last three characters.

substring("foobar", -2, 2)

The last two characters: start at -2, take two.

substring("foobar", 1.5, 2)

The fractional start position is truncated to 1.

substring("foobar", 0)

There is no position 0.

substring("foobar", 10)

A start position beyond the string is outside the domain. B-FEEL returns the empty string.

substring("foobar", 3, 100)

So is a length that runs past the end.

substring(null, 1)

A null input gives null in FEEL; B-FEEL returns the empty string.

Related functions

substring before · substring after · string length

Defined by the OMG DMN 1.6 specification, chapter 10.3.4 (built-in functions).