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.
This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book. Arguments and Return TypeName | Type | Description |
$sourceString |
xs:string? |
the entire string |
$startingLoc |
xs:double |
the starting character (1-based) |
$length |
xs:double |
the number of characters to include |
return value |
xs:string |
ExamplesXPath Example | 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 AlsoHistory |
Recommended Reading:
|