
XQuery String-length()
In XQuery, the fn:string-length()
function is used to determine the length of a given string. It takes a single argument, which is the string whose length you want to calculate, and returns an integer representing the number of characters in the string.
The basic syntax of the fn:string-length()
function is as follows:
fn:string-length($input-string)
$input-string
: The string for which you want to find the length.
Here’s an example of using fn:string-length()
in XQuery:
let $text := "Hello, World!"
let $length := fn:string-length($text)
return $length
Output:
13
In this example, the variable $text
contains the string “Hello, World!” The fn:string-length($text)
function calculates the length of the string and assigns it to the variable $length
. The output will be 13
, as there are 13 characters in the string, including spaces and punctuation.
Keep in mind that fn:string-length()
counts all characters in the string, including letters, digits, spaces, and any special characters. If the input string is empty, the function will return 0
.