Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/web/xpath/functions/substring-before/index.md
6517 views
---
title: substring-before slug: Web/XPath/Functions/substring-before
---

{{ XsltRef() }}

The substring-before function returns a string that is the part of a given string before a given substring.

Syntax

substring-before( haystack, needle )

Arguments

  • haystack

    • : The string to be evaluated. Part of this string will be returned.

  • needle

    • : The substring to search for. Everything before the first occurrence of needle in haystack will be returned.

Returns

A string.

Examples

XPath ExampleOutput
substring-before('aa-bb','-')aa
substring-before('aa-bb','a')(empty string)
substring-before('aa-bb','b')aa-
substring-before('aa-bb','q')(empty string)

Defined

XPath 1.0 4.2

Gecko support

Supported.