starts-with

Whether one string starts with another

Description

The fn:starts-with function returns an xs:boolean value indicating whether one string ($arg1) starts with the characters of another string ($arg2). Leading and trailing whitespace is significant, so you may want to use the fn:normalize-space function to trim the strings before using this function.

Parameters

Description

arg1:string()

the entire string to test

arg2:string()

the substring to check for

collation:string()

the collation to use for comparing

Examples

XPath

Results

starts-with('query', 'que')

true

starts-with('query', 'query')

true

starts-with('query', 'u')

false

starts-with('query', '')

true

starts-with('', 'query')

false

starts-with('', '')

true

starts-with('query', ())

true

starts-with(' query', 'q')

false

In a generator

Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-starts-with.

[e] example-starts-with
    [e] start
        [e] match
            [v] /
        [e] body
            [e] write-pattern
                [v] examples
    [e] patterns
        [e] examples
            [v] E01: {{ starts-with('query', 'que') }}
            [v] E02: {{ starts-with('query', 'query') }}
            [v] E03: {{ starts-with('query', 'u') }}
            [v] E04: {{ starts-with('query', '') }}
            [v] E05: {{ starts-with('', 'query') }}
            [v] E06: {{ starts-with('', '') }}
            [v] E07: {{ starts-with('query', ()) }}
            [v] E08: {{ starts-with(' query', 'q') }}

See Also