Finding the Length of a String

The length of a string can be determined using the string-length function. It accepts a single string and returns its length as an integer. Whitespace is significant, so leading and trailing whitespace characters are counted. Table 17-5 shows some examples.

Table 17-5. Examples of the string-length function

Example

Return value

string-length("query")

5

string-length(" query ")

9

string-length(normalize-space(" query "))

5

string-length("")

0

string-length(" ")

1

Get XQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.