Cover Image for XQuery String concat()
138 views

XQuery String concat()

In XQuery, the fn:concat() function is used to concatenate multiple strings into a single string. It takes two or more string arguments and returns a new string that is the result of concatenating all the input strings in the order they are provided.

Here’s the syntax of the fn:concat() function:

fn:concat($string1, $string2, ..., $stringN)
  • $string1, $string2, …, $stringN: The strings that you want to concatenate together.

Here’s an example of using fn:concat() in XQuery:

let $first := "Hello"
let $last := "World"
let $result := fn:concat($first, ", ", $last)
return $result

Output:

"Hello, World"

In this example, we have two strings stored in variables $first and $last. We use the fn:concat($first, ", ", $last) function to concatenate these strings together with a comma and space (“, “) in between, and the result is stored in the variable $result.

The fn:concat() function is useful when you need to join strings together without using any specific separator, as it simply concatenates the input strings in the order provided. If you want to use a specific separator between strings, you can use the fn:string-join() function, as shown in the previous response.

Keep in mind that the fn:concat() function only works with string arguments. If you have non-string values that you want to include in the concatenation, you may need to convert them to strings using the string() function before using fn:concat().

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS