Difference between revisions of "String Module"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
{{Announce|Updated with Version 10:}} Renamed from ''Strings Module'' to ''String Module''. The namespace URI has been updated as well. | {{Announce|Updated with Version 10:}} Renamed from ''Strings Module'' to ''String Module''. The namespace URI has been updated as well. | ||
− | This [[Module Library|XQuery Module]] contains functions for string computations. | + | This [[Module Library|XQuery Module]] contains functions for string operations and computations. |
=Conventions= | =Conventions= | ||
Line 7: | Line 7: | ||
All functions and errors in this module and errors are assigned to the <code><nowiki>http://basex.org/modules/string</nowiki></code> namespace, which is statically bound to the {{Code|string}} prefix.<br/> | All functions and errors in this module and errors are assigned to the <code><nowiki>http://basex.org/modules/string</nowiki></code> namespace, which is statically bound to the {{Code|string}} prefix.<br/> | ||
− | = | + | =Computations= |
==string:levenshtein== | ==string:levenshtein== | ||
Line 62: | Line 62: | ||
* <code>string:cologne-phonetic("Michael")</code> returns {{Code|645}} | * <code>string:cologne-phonetic("Michael")</code> returns {{Code|645}} | ||
* <code>every $s in ("Mayr", "Maier", "Meier") satisfies string:cologne-phonetic($s) = "67"</code> returns {{Code|true}} | * <code>every $s in ("Mayr", "Maier", "Meier") satisfies string:cologne-phonetic($s) = "67"</code> returns {{Code|true}} | ||
+ | |} | ||
+ | |||
+ | =Formatting= | ||
+ | |||
+ | {{Announce|The functions in this section have been adopted from the obsolete Output Module.}} | ||
+ | |||
+ | ==string:format== | ||
+ | |||
+ | {| width='100%' | ||
+ | |- valign="top" | ||
+ | | width='120' | '''Signatures''' | ||
+ | |{{Func|string:format|$format as xs:string, $items as item() ...|xs:string}}<br /> | ||
+ | |- valign="top" | ||
+ | | '''Summary''' | ||
+ | |Returns a formatted string. The remaining arguments specified by {{Code|$items}} are applied to the {{Code|$format}} string, according to [https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax Java’s printf syntax]. | ||
+ | |- valign="top" | ||
+ | | '''Errors''' | ||
+ | |{{Error|format|#Errors}} The specified format is not valid. | ||
+ | |- valign="top" | ||
+ | | '''Examples''' | ||
+ | | | ||
+ | * {{Code|string:format("%b", true())}} returns {{Code|true}}. | ||
+ | * {{Code|string:format("%06d", 256)}} returns {{Code|000256}}. | ||
+ | * {{Code|string:format("%e", 1234.5678)}} returns {{Code|1.234568e+03}}. | ||
+ | |} | ||
+ | |||
+ | ==string:cr== | ||
+ | |||
+ | {| width='100%' | ||
+ | |- valign="top" | ||
+ | | width='120' | '''Signatures''' | ||
+ | |{{Code|'''string:cr()''' as xs:string}} | ||
+ | |- valign="top" | ||
+ | | '''Summary''' | ||
+ | |Returns a single carriage return character ({{Code|&#13;}}). | ||
+ | |} | ||
+ | |||
+ | ==string:nl== | ||
+ | |||
+ | {| width='100%' | ||
+ | |- valign="top" | ||
+ | | width='120' | '''Signatures''' | ||
+ | |{{Code|'''string:nl()''' as xs:string}} | ||
+ | |- valign="top" | ||
+ | | '''Summary''' | ||
+ | |Returns a single newline character ({{Code|&#10;}}). | ||
+ | |} | ||
+ | |||
+ | ==string:tab== | ||
+ | |||
+ | {| width='100%' | ||
+ | |- valign="top" | ||
+ | | width='120' | '''Signatures''' | ||
+ | |{{Code|'''string:tab()''' as xs:string}} | ||
+ | |- valign="top" | ||
+ | | '''Summary''' | ||
+ | |Returns a single tabulator character ({{Code|&#9;}}). | ||
|} | |} | ||
Line 68: | Line 125: | ||
;Version 10.0 | ;Version 10.0 | ||
* Updated: Renamed from ''Strings Module'' to ''String Module''. The namespace URI has been updated as well. | * Updated: Renamed from ''Strings Module'' to ''String Module''. The namespace URI has been updated as well. | ||
+ | * Updated: {{Function||string:format}}, {{Function||string:cr}}, {{Function||string:nl}} and {{Function||string:tab}} adopted from the obsolete Output Module. | ||
− | The Module was introduced with Version 8.3. | + | The Module was introduced with Version 8.3. Functions were adopted from the obsolete Utility and Output Modules. |
Revision as of 14:36, 20 July 2022
Updated with Version 10: Renamed from Strings Module to String Module. The namespace URI has been updated as well.
This XQuery Module contains functions for string operations and computations.
Contents
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
Signatures | string:levenshtein($string1 as xs:string, $string2 as xs:string) as xs:double |
Summary | Computes the Damerau-Levenshtein Distance for two strings and returns a double value (0.0 - 1.0 ). The returned value is computed as follows:
|
Examples |
<syntaxhighlight lang="xquery"> let $norm := ft:normalize(?, map { 'stemming': true() }) return string:levenshtein($norm("HOUSES"), $norm("house")) </syntaxhighlight> |
string:soundex
Signatures | string:soundex($string as xs:string) as xs:string |
Summary | Computes the Soundex value for the specified string. The algorithm can be used to find and index English words with similar pronouncation. |
Examples |
|
string:cologne-phonetic
Signatures | string:cologne-phonetic($string as xs:string) as xs:string |
Summary | Computes 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 |
|
Formatting
The functions in this section have been adopted from the obsolete Output Module.
string:format
Signatures | string:format($format as xs:string, $items as item() ...) as xs:string |
Summary | Returns a formatted string. The remaining arguments specified by $items are applied to the $format string, according to Java’s printf syntax.
|
Errors | format : The specified format is not valid.
|
Examples |
|
string:cr
Signatures | string:cr() as xs:string
|
Summary | Returns a single carriage return character ( ).
|
string:nl
Signatures | string:nl() as xs:string
|
Summary | Returns a single newline character ( ).
|
string:tab
Signatures | string:tab() as xs:string
|
Summary | Returns a single tabulator character (	 ).
|
Changelog
- Version 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
andstring:tab
adopted from the obsolete Output Module.
The Module was introduced with Version 8.3. Functions were adopted from the obsolete Utility and Output Modules.