home contribute faq download

FunctX XQuery Functions

functx:index-of-string-first

The first position of a substring

Google
Webxqueryfunctions.com

Description

The functx:index-of-string-first function returns an integer representing the first position of $substring within $arg. If $arg does not contain $substring, the empty sequence is returned.

Arguments and Return Type

NameTypeDescription
$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-first 
  ( $arg as xs:string? ,
    $substring as xs:string )  as xs:integer? {
       
  if (contains($arg, $substring))
  then string-length(substring-before($arg, $substring))+1
  else ()
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function index-of-string-first 
  ( $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
  else ()
 }

Examples

XQuery ExampleResults
functx:index-of-string-first(
   'abcdabcdabcd','abc')
1
functx:index-of-string-first(
   'abcd','abc')
1
functx:index-of-string-first(
   'xxx','abc')
()

See Also

functx:index-of-stringThe position(s) of a substring
functx:index-of-string-lastThe last position of a substring
fn:containsWhether one string contains another

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley