Main Page » XQuery » Functions » String Functions

String Functions

This module contains functions for string operations and computations.

Conventions

All functions and errors in this module and errors are assigned to the http://basex.org/modules/string namespace, which is statically bound to the string prefix.

Computations

string:levenshtein

Signature
string:levenshtein(
  $string1  as xs:string,
  $string2  as xs:string
) as xs:double
SummaryComputes the Damerau-Levenshtein Distance for $string1 and $string2 and returns a normalized double value (0 – 1). The returned value is computed as follows:
  • 1 – distance / max(lengths of strings)
  • 1 is returned if the strings are equal; 0 is returned if the strings are too different.
Errors
boundsThe specified string exceeds the maximum supported length.
Examples
string:levenshtein("flower", "flowers")
Result: 0.8571428571428571e0
let $norm := ft:normalize(?, { 'stemming': true() })
return string:levenshtein($norm("HOUSES"), $norm("house"))
1 is returned after the input has been normalized (words are stemmed, converted to lower case, and diacritics are removed).

string:jaro-winkler

Signature
string:jaro-winkler(
  $string1  as xs:string,
  $string2  as xs:string
) as xs:double
SummaryComputes the Jaro-Winkler Distance for $string1 and $string2 and returns a double value (0 – 1). 1 is returned if the strings are equal; 0 is returned if the strings are too different.
Examples
string:jaro-winkler("flower", "flowers")
Result: 0.98e0
let $norm := ft:normalize(?, { 'stemming': true() })
return string:jaro-winkler($norm("HOUSES"), $norm("house"))
1 is returned after the input has been normalized (words are stemmed, converted to lower case, and diacritics are removed).

string:soundex

Signature
string:soundex(
  $string  as xs:string
) as xs:string
SummaryComputes the Soundex value for the specified string. The algorithm can be used to find and index English words with similar pronouncation.
Examples
string:soundex("Michael")
Result: 'M240'
string:soundex("OBrien") = string:soundex("O'Brien")
Result: true()

string:cologne-phonetic

Signature
string:cologne-phonetic(
  $string  as xs:string
) as xs:string
SummaryComputes the Kölner Phonetik value for the specified string. Similar to Soundex, the algorithm is used to find similarly pronounced words, but for the German language. As the first returned digit can be 0, the value is returned as string.
Examples
string:cologne-phonetic("Michael")
Result: '645'
every $s in ("Mayr", "Maier", "Meier")
satisfies string:cologne-phonetic($s) = "67"
Result: true()

Formatting

string:format

Signature
string:format(
  $pattern    as xs:string,
  $values...  as item()
) as xs:string
SummaryReturns a formatted string. The remaining $values are incorported into the $pattern, according to Java’s printf syntax.
Errors
formatThe specified format is invalid.
Examples
string:format("%b", true())
Result: 'true'
string:format("%06d", 256)
Result: '000256'
string:format("%e", 1234.5678)
Result: '1.234568e+03'

Errors

CodeDescription
boundsThe specified string exceeds the maximum supported length.
formatThe specified format is invalid.

Changelog

Version 11.0Version 10.0
  • Updated: Renamed from Strings Module to String Module. The namespace URI has been updated as well.
  • Updated: string:format, string:cr, string:nl and string:tab adopted from the obsolete Output Module.
Version 8.3
  • Added: New module added. Functions were adopted from the obsolete Utility and Output Modules.

⚡Generated with XQuery