Concatenating and Splitting Strings

Five functions, summarized in Table 17-6, concatenate and split apart strings.

Table 17-6. Functions that concatenate and split apart strings




Concatenates two or more strings


Concatenates a sequence of strings, optionally using a separator


Breaks a single string into a sequence of strings, using a specified separator


Converts a sequence of Unicode code-point values to a string


Converts a string to a sequence of Unicode code-point values

Concatenating Strings

Strings can be concatenated together using one of two functions: concat or string-join. XQuery does not allow use of concat operators such as +, &, or || to concatenate strings. The concat function accepts individual string arguments and concatenates them together. This function is unique in that it accepts a variable number of arguments. For example:

concat("a", "b", "c")

returns the string abc. The string-join function, on the other hand, accepts a sequence of strings. For example:

string-join( ("a", "b", "c"), "")

also returns the string abc. In addition, string-join allows a separator to be passed as the second argument. For example:

string-join( ("a", "b", "c"), "/")

returns the string a/b/c.

Splitting Strings Apart

Strings can be split apart, or tokenized, using the tokenize function. This function breaks a string into a sequence of strings, using a regular expression to designate ...

Get XQuery now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.