substring-before function
The fn:substring-before function returns a substring that occurs in a string before the first occurrence of a specific search string. The search string is matched using the default collation.
Syntax
- source-string
- The string from which the substring is retrieved.
source-string has the xs:string data type, or is an empty sequence. If source-string is an empty sequence, source-string is set to a string of length 0.
- search-string
- The string whose first occurrence in source-string is
to be searched for.
search-string has the xs:string data type, or is an empty sequence.
- Limitation of length
The length of search-string is limited to 32000 bytes.
Returned value
If source-string is
not the empty sequence or a string of length 0:
- If search-string is found at position m of source-string, and m>1, the returned value is the substring that begins at position 1, and ends at position m of source-string.
- If search-string is found at position 1 of source-string, the returned value is a string of length 0.
- If search-string is an empty sequence or a string of length 0, the returned value is a string of length 0.
- If search-string is not found in source-string, the returned value is a string of length 0.
If source-string is the empty sequence or a string of length 0, the returned value is a string of length 0.
Example
The following function finds the characters before 'ABC' in string to 'DEFABCD' using the default collation.
fn:substring-before('DEFABCD', 'ABC')The returned value is 'DEF'.
