How do I remove a new-line/return from the end of a variable? I tried functx:substring-before-last
to try and remove the new line (denoting it as \r
, \n
and also as \r\n
) but still when I output that variable's value, the newline is still there in it.
XQuery: removing newline/return character from end of a string stored in a variable in query
10.8k Views Asked by Arvind At
2
There are 2 best solutions below
2

CR and NL can be specified as
and
. The following regular expression will remove all trailing newlines from your input string:
replace($string, '(
?
)*$', '')
If you want to normalize all whitespaces of a string, normalize-string
is another, more readable option:
normalize-space($string)
You can either use
fn:normalize-space($arg as xs:string?)
to remove all additional whitespace:Or you can just use
fn:replace(..)
and a regular expression: