substring

A substring based on a starting point and optional length

Description

The fn:substring function uses the $startingLoc argument to determine the starting location for the substring, where the first character is at position 1 (not 0). The optional $length argument indicates the number of characters to include, relative to the starting location. If no $length is provided, the entire rest of the string is included.

The function returns all characters whose position is greater than or equal to $startingLoc and less than ($startingLoc + $length). The $startingLoc number can be zero or negative, in which case the function starts at the beginning of the string, and still only include characters up to (but not including) the position at ($startingLoc + $length). If ($startingLoc + $length)is greater than the length of the string, the entire rest of the string is included.

Parameters

Description

sourceString:string()

the entire string

startingLoc:double()

the starting character (1-based)

length:double()

the number of characters to include

Examples

XPath

Results

substring(‘query’, 1)

query

substring(‘query’, 3)

ery

substring(‘query’, 1, 1)

q

substring(‘query’, 2, 3)

uer

substring(‘query’, 2, 850)

uery

substring(‘query’, 6, 2)

zero-length string

substring(‘query’, -2)

query

substring(‘query’, -2, 5)

qu

substring(‘query’, 1, 0)

zero-length string

substring(‘’, 1)

zero-length string

substring((), 1)

zero-length string

See Also