# fn:substring - XPath XQuery Reference

Returns the portion of the value of $sourceString beginning at the position
            indicated by the value of $start and continuing for the number of characters indicated by the value of
            $length.deterministiccontext-independentfocus-independentIf the value of $sourceString is the empty sequence, the function returns
            the zero-length string. Otherwise, the function returns a string comprising those characters of $sourceString whose index position (counting
            from one) is greater than or equal to the value of $start (rounded to an
            integer), and (if $length is specified) less than the sum of
               $start and $length (both rounded to integers).The characters returned do not extend beyond $sourceString. If
               $start is zero or negative, only those characters in positions greater
            than zero are returned.More specifically, the three argument version of the function returns the characters in
               $sourceString whose position $p satisfies:fn:round($start) <= $p and $p < fn:round($start) + fn:round($length)The two argument version of the function assumes that $length is infinite
            and thus returns the characters in
               $sourceString whose position $p satisfies:fn:round($start) <= $pIn the above computations, the rules for op:numeric-less-than and
               op:numeric-greater-than apply.fn:substring("motor car", 6)" car"Characters starting at position 6 to the end of
                     $sourceString are selected.fn:substring("metadata", 4, 3)"ada"Characters at positions greater than or equal to 4 and less than 7 are
                  selected.fn:substring("12345", 1.5, 2.6)"234"Characters at positions greater than or equal to 2 and less than 5 are
                  selected.fn:substring("12345", 0, 3)"12"Characters at positions greater than or equal to 0 and less than 3 are
                  selected. Since the first position is 1, these are the characters at positions 1
                  and 2.fn:substring("12345", 5, -3)""Characters at positions greater than or equal to 5 and less than 2 are
                  selected.fn:substring("12345", -3, 5)"1"Characters at positions greater than or equal to -3 and less than 2
                  are selected. Since the first position is 1, this is the character at position
                  1.fn:substring("12345", 0 div 0E0, 3)""Since 0 div 0E0 returns NaN, and
                     NaN compared to any other number returns false, no
                  characters are selected.fn:substring("12345", 1, 0 div 0E0)""As above.fn:substring((), 1, 3)""fn:substring("12345", -42, 1 div 0E0)"12345"Characters at positions greater than or equal to -42 and less than
                     INF are selected.fn:substring("12345", -1 div 0E0, 1 div 0E0)""Since the value of -INF + INF is NaN, no
                  characters are selected.The first character of a string is located at position 1, not position 0.The second and third arguments allow xs:double values (rather than
         requiring xs:integer) in order to achieve compatibility with XPath 1.0.A surrogate pair counts as one character, not two.The consequences of supplying values such as NaN or positive or negative
         infinity for the $start or $length arguments follow from the
         above rules, and are not always intuitive.