fn: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 position in source-string of the substring. The first position of source-string is 1. If start<=0, start is set to 1.

start has the xs:double data type.

length
The length 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.

length has the xs:double data type.

Returned value

If source-string is not the empty sequence, the returned value is an xs:string value that is the substring of source-string that starts at position start and is length bytes. 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'.