Reputation: 6474
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.
Upvotes: 0
Views: 11108
Reputation: 6229
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)
Upvotes: 2
Reputation: 4241
You can either use fn:normalize-space($arg as xs:string?)
to remove all additional whitespace:
Summary: Returns the value of
$arg
with whitespace normalized by stripping leading and trailing whitespace and replacing sequences of one or more than one whitespace character with a single space,#x20
.
Or you can just use fn:replace(..)
and a regular expression:
fn:replace($string, '(\r?\n|\r)$', '')
Upvotes: 4