How to remove line feed and carriage return from start and end, but not from the middle of a string
Hello,
Thanks for reading this question.
We need to remove the line feeds and carriage returns from start and end, but not from the middle of a string
We have tested the following ways:
set output = $ZStrip("[line feed](carriage return) str [line feed](carriage return) ing [line feed](carriage return)","<>C")
ObjectScriptObjectScript
But it removes also control characters which we need to preserve...
Also we have tested:
set output = $REPLACE("[line feed](carriage return) str [line feed](carriage return) ing [line feed](carriage return)",$C(13,10),"")
ObjectScriptObjectScript
But it deletes line feed and carriage return at the middle of the string, so it is not what we need...
How would you recommend us to implement it.
We have read:
https://community.intersystems.com/post/trimming
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
https://community.intersystems.com/post/zstrip-clean-string
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
Could you help us please?
Thanks.
F Q:$c(10,13)'[$e(str)!'$L(str) s $e(str)="" // strip $c(10) and $c(13) from front
F Q:$c(10,13)'[$e(str,*)!'$l(str) s $e(str,*)="" // strip $c(10) and $c(13) from end
There are multiple line feeds and carriage returns not only one at start and at end
Yes, and it will remove all those from the front and all those from the end, preserving those in the middle.
If you know that it begins and ends with CRLF then it is as simple as:
There are multiple line feeds and carriage returns not only one at start and at end
Yes - this will work in that case above case (see my example which preserves all of them in the middle)
@Yone Moreno
Did you try $ZSTRIP with the following arguments?
Set string = $ZSTRIP(string,"<>",$CHAR(13,10))
$ZSTRIP without a mask code in the second argument and with specific characters as the third argument will strip just those specific characters.