# xf:substring-before

Finds the substring that precedes $string-var2 in $string-var1.

### Signatures

xf:substring-before(xs:string? $string-var1, xs:string? $string-var2) —> xs:string?

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string? | $string-var1 | Represents the source string.
xs:string? | $string-var2 | Represents the comparison string.

### Returns

Returns the part of the $string-var1 source string that precedes $string-var2.

Returns the value of $string-var1, if $string-var2 is a zero-length string ("").

Returns a zero-length string (""), if $string-var1 does not contain $string-var2.

If the value of $string-var1 or $string-var2 is an empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

### Examples

This Query . . . | Generates This Result . . .
--- | ---
<r>{xf:substring-before("super", "p")}</r> | <r>su</r>
<r>{xf:substring-before("super", "")}</r> | <r>super</r>
<r>{xf:substring-before("super", "z")}</r> | <r/>
<r>{xf:substring-before("super", ())}</r> | <r/>

Related Topics

W3C substring-before function description.