View raw Markdown
type: fhirpath-functionfunction: substringcategory: String Manipulationsection: 5.6.3source: fhirpath/functions.json

FHIRPath Function: substring

Returns the part of the string starting at position start (zero-based). If length is given, will return at most length number of characters from the input string.

If start lies outside the length of the string, the function returns empty ({ }). If there are less remaining characters in the string than indicated by length, the function returns just the remaining characters.

If the input or start is empty, the result is empty.

If an empty length is provided, the behavior is the same as if length had not been provided.

If a negative or zero length is provided, the function returns an empty string ('').

If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.

'abcdefg'.substring(3) // 'defg'
'abcdefg'.substring(1, 2) // 'bc'
'abcdefg'.substring(6, 2) // 'g'
'abcdefg'.substring(7, 1) // { } (start position is outside the string)
'abcdefg'.substring(-1, 1) // { } (start position is outside the string,
                           //     this can happen when the -1 was the result of a calculation rather than explicitly provided)
'abcdefg'.substring(3, 0) // '' (empty string)
'abcdefg'.substring(3, -1) // '' (empty string)
'abcdefg'.substring(-1, -1) // {} (start position is outside the string)

Summary

Description

Returns the part of the string starting at position start (zero-based). If length is given, will return at most length number of characters from the input string.

Arguments

Type Mapping

Example

'abcdefg'.substring(3) // 'defg'
'abcdefg'.substring(1, 2) // 'bc'