substring function

The fn:substring function returns a substring of a string.

Syntax

Read syntax diagramSkip visual syntax diagramfn:substring( source-string, start, length)
source-string
The string from which the substring is retrieved.

source-string has the xs:string data type, or is an empty sequence.

start
The starting character position in source-string of the substring. The first position of source-string is 1. If start<= 0, start is set to 1. Code points above xFFFF, which use two 16-bit values known as a surrogate pairs, are counted as one character.

start has the xs:double data type.

length
The length in characters of the substring. The default for length is the length of source-string. If start+length-1 is greater than the length of source-string, length is set to (length of source-string)-start+1. Code points above xFFFF, which use two 16-bit values known as a surrogate pairs, are counted as one character in the length of the string.

length has the xs:double data type.

Returned value

If source-string is not the empty sequence, the returned value is a substring of source-string that starts at character position start and has length characters. If source-string is the empty sequence, the result is a string of length 0.

Example

The following function returns seven characters starting at the sixth character of the string 'Test literal'.
fn:substring('Test literal',6,7)

The returned value is 'literal'.