Description
The functx:index-of-string function returns one or more integers representing the position of a $substring within $arg. Overlapping substrings are not counted. If $arg does not contain $substring, the empty sequence is returned.
Arguments and Return Type| Name | Type | Description |
$arg |
xs:string? |
the string |
$substring |
xs:string |
the substring to find |
| return value |
xs:integer* |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for July 2004 - January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:index-of-string
( $arg as xs:string? ,
$substring as xs:string ) as xs:integer* {
if (contains($arg, $substring))
then (string-length(substring-before($arg, $substring))+1,
for $other in
functx:index-of-string(substring-after($arg, $substring),
$substring)
return
$other +
string-length(substring-before($arg, $substring)) +
string-length($substring))
else ()
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function index-of-string
( $arg as xs:string? ,
$substring as xs:string ) as xs:integer* {
if (fn:contains($arg, $substring))
then (fn:string-length(fn:substring-before($arg, $substring))+1,
for $other in
functx:index-of-string(fn:substring-after($arg, $substring),
$substring)
return
$other +
fn:string-length(fn:substring-before($arg, $substring)) +
fn:string-length($substring))
else ()
} |
Examples| XQuery Example | Results |
|---|
functx:index-of-string('abcdabcdabcd','abc')
|
(1, 5, 9)
|
functx:index-of-string('abcd','abc')
|
1
|
functx:index-of-string('xxx','abc')
|
()
|
See AlsoHistory |
|