home contribute faq download

FunctX XQuery Functions

functx:reverse-string

Reverses the order of characters

Google
Webxqueryfunctions.com

Description

The functx:reverse-string function reverses the order of characters in a string. It returns a zero-length string if the argument is the empty sequence.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string to reverse
return value xs:string

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for April 2005 - January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:reverse-string 
  ( $arg as xs:string? )  as xs:string {
       
   codepoints-to-string(reverse(string-to-codepoints($arg)))
 } ;
XQuery Syntax for July 2004:
declare namespace functx = "http://www.functx.com"; 
declare function functx:reverse-string 
  ( $arg as xs:string? )  as xs:string {
       
   string-join(
   for $i in (0 to (string-length($arg) - 1))
   return substring($arg, string-length($arg) - $i,1), '')
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function reverse-string 
  ( $arg as xs:string? )  as xs:string {
       
   fn:string-join(
   for $i in (0 to (fn:string-length($arg) - 1))
   return fn:substring($arg, fn:string-length($arg) - $i,1), '')
 }

Examples

XQuery ExampleResults
functx:reverse-string('abc')
cba
functx:reverse-string('a')
a

See Also

fn:reverseReverses the order of a sequence

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