Remove Carriage Returns

305 views
Skip to first unread message

Neerav Verma

unread,
Jan 5, 2010, 7:04:55 PM1/5/10
to Ensemble Group
What would be the command to replace carriage returns with space

I was trying Zstrip but it seems to not work

Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Stephen Leacock  - "I detest life-insurance agents: they always argue that I shall some day die, which is not so."

Neerav Verma

unread,
Jan 5, 2010, 7:26:49 PM1/5/10
to Ensemble Group
$ZSTRIP(rset.GetDataByName("Comment"), "*WC"

This only replaces it

Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Jonathan Swift  - "May you live every day of your life."

htg

unread,
Jan 5, 2010, 7:33:41 PM1/5/10
to InterSystems: Ensemble in Healthcare
$TRANSLATE(rset.GetDataByName("Comment"),$C(13,10)," ")

should replace <CR> by <blank> and remove <lf>

Andre Cerri

unread,
Jan 5, 2010, 10:44:53 PM1/5/10
to ensemble-in...@googlegroups.com
Nope, that will replace $c(13) with space and $c(10) with null.

CCL>set x=$c(13,10,10,13)

CCL>set y= $tr(x,$c(13,10)," ")

CCL>w $l(y)
2
CCL>w $a($e(y,1))
32
CCL>w $a($e(y,2))
32

Try:

CL>set x=$c(13,10,10,13)

CL>set y= $replace(x,$c(13,10)," ")

CL>w $l(y)
3
CL>w $a($e(y,1))
32
CL>w $a($e(y,2))
10
CL>w $a($e(y,3))
13

HTH

André

htg

unread,
Jan 6, 2010, 5:33:43 AM1/6/10
to InterSystems: Ensemble in Healthcare
???

On Tue, Jan 5, 2010 at 7:04 PM, Neerav Verma <vne...@gmail.com>
wrote:
What would be the command to replace carriage returns with space

On Jan 6, 4:44 am, Andre Cerri <andre.ce...@intersystems.com> wrote:
Nope, that will replace $c(13) with space and $c(10) with null.

??? so what's your message ???
the additionl removal of <lf> = $c(10) ?

Ted Peck

unread,
Jan 6, 2010, 11:37:20 AM1/6/10
to ensemble-in...@googlegroups.com
I also didn't understand what Andre meant to say, but his example
demonstrates the solution to the original question as I understood it.
The question was how to "Remove Carriage Returns", replacing them with
spaces and discarding linefeeds.

This simple $TRanslate() function does it:

CCL>Set original=$C(13,10,10,13)

CCL>Set cleaned = $TR(original,$C(13,10)," ")

CCL>w $L(cleaned)
2
CCL>w $A($E(cleaned,1))
32
CCL>w $a($E(cleaned,2))
32


Ted

----- Original Message -----
From: "htg" <herman...@googlemail.com>
To: "InterSystems: Ensemble in Healthcare"
<Ensemble-in...@googlegroups.com>
Sent: Wednesday, January 06, 2010 5:33 AM
Subject: [InterSystems-EnsHlth] Re: Remove Carriage Returns


--------------------------------------------------------------------------------


> --
> You received this message because you are subscribed to the Google Groups
> "InterSystems: Ensemble in Healthcare Community" group.
> To post to this group, send email to
> Ensemble-in...@googlegroups.com
> To unsubscribe from this group, send email to
> Ensemble-in-Healt...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/Ensemble-in-Healthcare?hl=en

Andre Cerri

unread,
Jan 6, 2010, 2:33:02 PM1/6/10
to ensemble-in...@googlegroups.com
The original question was how to replace carriage returns with spaces, so we both misread it!

She didn't say anything about linefeeds.

$TR(original,$C(13)," ")

Neerav Verma

unread,
Jan 6, 2010, 2:59:42 PM1/6/10
to ensemble-in...@googlegroups.com
In case you were referring to me. I  am He not She ;)

Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Charles de Gaulle  - "The better I get to know men, the more I find myself loving dogs."

Andre Cerri

unread,
Jan 6, 2010, 3:21:00 PM1/6/10
to ensemble-in...@googlegroups.com
Oh, sorry Neerav, I thought I saw someone refer to you as 'she' in a previous post. Apologies.


From: ensemble-in...@googlegroups.com [mailto:ensemble-in...@googlegroups.com] On Behalf Of Neerav Verma
Sent: Wednesday, January 06, 2010 3:00 PM

Neerav Verma

unread,
Jan 6, 2010, 4:07:19 PM1/6/10
to ensemble-in...@googlegroups.com
No Worries

Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Stephen Leacock  - "I detest life-insurance agents: they always argue that I shall some day die, which is not so."

eric

unread,
Jan 11, 2010, 3:46:42 PM1/11/10
to InterSystems: Ensemble in Healthcare
Hi everybody,

i have a problem for you.

I want to Remove Carriage Returns into streams (for example the below
stream is taken by EnsLib.File.InboundAdapter)

H|~^\&|8040200007||1~DXLAB||ORU|||2~SRA||P|H2.1|200804021123|
P|1|110050131|141289|89000056|POISSON~PANE~~~MLLE~||19870214|
F|||||||||||||||20080326~20080326||
OBR|7|080400007|~51179|RCTH~Ren.cliniques axe thyroidien~L|S||
200804021151||||N|||200804021151||~~~9035||||||||~LABORATOIRE Central|
F|
OBX|1|ST|RCTH~Ren.cliniques axe thyroidien(Renseignements cliniques)
~L||petit commentaire pour tester que tout passe...||||||F||||
HORMONOLOGIE~10~ETUDE DE L' AXE THYROIDIEN~4~RCTH~1~1|OLWATT
OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo
thyroïdien ?)~L||cher docteur, cette ligne de commentaire sert à
tester le retour charriot~si ca passe c'est que le retour charriot
n'est plus un problème|||
A||||F||||HORMONOLOGIE~10~ETUDE DE L' AXE THYROIDIEN~4~RCTH~1~2|OLWATT
L|1||1|6

I have created a BS with in Method OnProcessInput(pInput As
%RegisteredObject,pOutput As %RegisteredObject) :

set pTargetStream=##class(%FileCharacterStream).%New()

// Suppression des retours chariots (à tester)
set identifier=$C(13)
set associator=""
set tSC=##class(DemoSante.Util.EnsUtils).Translate(pInput,
pTargetStream, identifier, associator)
set tSC=pTargetStream.%Save()

with
ClassMethod Translate(
sourceStream As %FileCharacterStream,
targetStream As %FileCharacterStream,
identifier As %String,
associator As %String = "") As %Status
{
while 'sourceStream.AtEnd {
set sourceLine=sourceStream.ReadLine()
set targetLine=$TRANSLATE(sourceLine,identifier,associator)
set tSC=targetStream.WriteLine(targetLine)
}
quit tSC
}

and the result is

H|~^\&|8040200007||1~DXLAB||ORU|||2~SRA||P|H2.1|200804021123|
P|1|110050131|141289|89000056|POISSON~PANE~~~MLLE~||19870214|
F|||||||||||||||20080326~20080326||
OBR|7|080400007|~51179|RCTH~Ren.cliniques axe thyroidien~L|S||
200804021151||||N|||200804021151||~~~9035||||||||~LABORATOIRE Central|
F|
OBX|1|ST|RCTH~Ren.cliniques axe thyroidien(Renseignements cliniques)
~L||petit commentaire pour tester que tout passe...||||||F||||
HORMONOLOGIE~10~ETUDE DE L' AXE THYROIDIEN~4~RCTH~1~1|OLWATT
OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo
thyroïdien ?)~L||cher docteur, cette ligne de commentaire sert à
tester le retour charriot~si ca passe c'est que le retour charriot
n'est plus un problème|||||||
L|1||1|6

the carriage return has been replaced by "" but the others caracters
have not be taken into account.

Have you a solution ?

Thank you

Regards

Eric Sebelin

On 6 jan, 22:07, Neerav Verma <vnee...@gmail.com> wrote:
> No Worries
>
> Thank You,
>
> Neerav Vermahttp://www.linkedin.com/in/vneerav
> ------------------------------------------------------

> Stephen Leacock<http://www.brainyquote.com/quotes/authors/s/stephen_leacock.html>


> - "I detest life-insurance agents: they always argue that I shall some
> day
> die, which is not so."
>

> On Wed, Jan 6, 2010 at 3:21 PM, Andre Cerri <andre.ce...@intersystems.com>wrote:
>
>
>
> >  Oh, sorry Neerav, I thought I saw someone refer to you as 'she' in a
> > previous post. Apologies.
>

> >  ------------------------------
> > *From:* ensemble-in...@googlegroups.com [mailto:
> > ensemble-in...@googlegroups.com] *On Behalf Of *Neerav Verma
> > *Sent:* Wednesday, January 06, 2010 3:00 PM
>
> > *To:* ensemble-in...@googlegroups.com
> > *Subject:* Re: [InterSystems-EnsHlth] Re: Remove Carriage Returns


>
> > In case you were referring to me. I  am He not She ;)
>
> > Thank You,
>
> > Neerav Verma
> >http://www.linkedin.com/in/vneerav
> > ------------------------------------------------------

> > Charles de Gaulle<http://www.brainyquote.com/quotes/authors/c/charles_de_gaulle.html> - "The better I get to know men, the more I find myself loving dogs."

> >> On Tue, Jan 5, 2010 at 7:04 PM, Neerav Verma <vnee...@gmail.com>


> >> wrote:
> >> What would be the command to replace carriage returns with space
>
> >> On Jan 6, 4:44 am, Andre Cerri <andre.ce...@intersystems.com> wrote:
> >> Nope, that will replace $c(13) with space and $c(10) with null.
>
> >> ??? so what's your message ???
> >> the additionl removal of <lf> = $c(10) ?
>

> >> ---------------------------------------------------------------------------­-----

> >http://groups.google.com/group/Ensemble-in-Healthcare?hl=en- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Neerav Verma

unread,
Jan 11, 2010, 3:49:12 PM1/11/10
to ensemble-in...@googlegroups.com
This is what I did to remove all control characters and replace them by space
You can choose to control what you remove and the c(13) should be carriage return

$TRANSLATE(rset.GetData(9),$C(13,10)," ")



Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Marie von Ebner-Eschenbach  - "Even a stopped clock is right twice a day."

Ted Peck

unread,
Jan 11, 2010, 5:12:26 PM1/11/10
to ensemble-in...@googlegroups.com
By using methods ReadLine() and WriteLine() your code is automatically
removing and re-inserting some kind of newline character, depending on your
OS. You should use just Read() and Write().


Hi everybody,

set pTargetStream=##class(%FileCharacterStream).%New()

and the result is

Thank you

Regards

Eric Sebelin

--------------------------------------------------------------------------------

eric

unread,
Jan 12, 2010, 10:53:35 AM1/12/10
to InterSystems: Ensemble in Healthcare
Thank you for your answers, i did :

set sourceLine=pInput.Read()
set pTa=$TRANSLATE(sourceLine,$C(13)," ")
set tSC=pTargetStream.WriteLine(pTa)
set tSC=pTargetStream.%Save()

and the result is : the carriage return is remplaced by " " but after
this carriage return until end of this line, i have no character :

for example :

OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo
thyroïdien ?)~L||cher docteur, cette ligne de commentaire sert à
tester le retour charriot~si ca passe c'est que le retour charriot
n'est plus un problème|||
A||||F||||HORMONOLOGIE~10~ETUDE DE L' AXE THYROIDIEN~4~RCTH~1~2|
OLWATT

the carriage return is after A character third line and the result
obtained :

OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo
thyroïdien ?)~L||cher docteur, cette ligne de commentaire sert à
tester le retour charriot~si ca passe c'est que le retour charriot
n'est plus un problème||| ||||||||

I want :

OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo
thyroïdien ?)~L||cher docteur, cette ligne de commentaire sert à
tester le retour charriot~si ca passe c'est que le retour charriot

n'est plus un problème||| ||||F||||HORMONOLOGIE~10~ETUDE DE L' AXE
THYROIDIEN~4~RCTH~1~2|OLWATT

Have you an idea ?

Regards

Eric Sebelin

> > >http://groups.google.com/group/Ensemble-in-Healthcare?hl=en-Masquer le


> > >texte des messages précédents -
>
> > - Afficher le texte des messages précédents -
>

> ---------------------------------------------------------------------------­-----
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "InterSystems: Ensemble in Healthcare Community" group.
> > To post to this group, send email to
> > Ensemble-in...@googlegroups.com
> > To unsubscribe from this group, send email to
> > Ensemble-in-Healt...@googlegroups.com
> > For more options, visit this group at

Dale du Preez

unread,
Jan 13, 2010, 5:28:20 AM1/13/10
to ensemble-in...@googlegroups.com
Eric,

I am not sure if Google translated out any special characters, but it
may be easier if you indicate any special characters in your incoming
data, and what you want the output to look like. Something like:
Incoming data:


OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néothyroïdien

?)~L||cher docteur, cette ligne de commentaire sert àtester le retour

charriot~si ca passe c'est que le retour charriotn'est plus un

problème|||[CarriageReturn][NewLine]


A||||F||||HORMONOLOGIE~10~ETUDE DE L' AXE THYROIDIEN~4~RCTH~1~2|OLWATT

etc.

I suspect part of the problem may be due to the fact that you are using
WriteLine() for output - the exact behaviour in this case will depend on
the terminators defined for your target stream.

Hopefully we can get to the bottom of this one.

Dale

eric

unread,
Jan 13, 2010, 6:36:45 AM1/13/10
to InterSystems: Ensemble in Healthcare
Hi Dale,

I test these commands:

set sourceLine=pInput.Read()
set pTa=$TRANSLATE(sourceLine,$C(13)," ")

set tSC=pTargetStream.Write(pTa)
set tSC=pTargetStream.%Save()

with incoming data :
...


OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo
thyroïdien ?)~L||cher docteur, cette ligne de commentaire sert à
tester le retour charriot~si ca passe c'est que le retour charriot

n'est plus un problème|||[CarriageReturn][NewLine]
A||||F||||HORMONOLOGIE~10~ETUDE DE L' AXE THYROIDIEN~4~RCTH~1~2|OLWATT

[CarriageReturn][NewLine]
...

and i obtain :


OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo

thyroïdien ?)~L||cher docteur. cette ligne de commentaire sert à


tester le retour charriot~si ca passe c'est que le retour charriot

n'est plus un problème||| ||||||||[CarriageReturn][NewLine]

i want to obtain :


OBX|2|ST|RCTHK~Ren.cliniques axe thyroidien(Présence d'un néo

thyroïdien ?)~L||cher docteur. cette ligne de commentaire sert à


tester le retour charriot~si ca passe c'est que le retour charriot
n'est plus un problème|||A||||F||||HORMONOLOGIE~10~ETUDE DE L' AXE

THYROIDIEN~4~RCTH~1~2|OLWATT[CarriageReturn][NewLine]

Have you a solution ?

Regards,

Eric Sebelin

> ...
>
> plus de détails »- Masquer le texte des messages précédents -

htg

unread,
Jan 13, 2010, 9:02:01 AM1/13/10
to InterSystems: Ensemble in Healthcare
some suggestions:
1)
> set pTa=$TRANSLATE(sourceLine,$C(13)," ")
This just removes [CarriageReturn] but not [NewLine]
and may cause strange display effects
change to:
set pTa=$TRANSLATE(sourceLine,$C(13,10)," ")
so also [NewLine] is removed.
2)
use GlobalBinaryStream instead of GlobalCharacterStream
to eliminate any embedded terminator control

to verify the content of pTa use ZZDUMP pTa if in Terminal mode.
if not:
Open 1 use 1 ZZDUMP pTa Close 1
and see the result in cconsole.log

if you dislike spamming cconsole.log:
set file="c:\temp\mydump.txt" or equivalent in unix
Open file:("WNS") use file ZZDUMP pTa close file

eric

unread,
Jan 14, 2010, 9:57:46 AM1/14/10
to InterSystems: Ensemble in Healthcare
Thank you,
with
set sourceLine = pInput.Read()
set pTa = $TRANSLATE(sourceLine,$C(13),"")
//$$$LOGINFO("pTa "_pTa)
//Open 1 use 1 ZZDUMP pTa Close 1
set tSC = pTargetStream.Write(pTa)
set tSC = pTargetStream.%Save()

i remove all carriage returns as :

H|~^\&|8040200007||1~DXLAB||OR[CarriageReturn]
U|||2~SRA||P|H2.1|200804021123|[CarriageReturn][NewLine]
P|1|110071393|188728|107040448|COSBANN~FRANCOISE~~~MLLE~||19450628|
F|||||||||||||||20071211~20071211||[CarriageReturn][NewLine]

becomes

H|~^\&|8040200007||1~DXLAB||ORU|||2~SRA||P|H2.1|200804021123|[NewLine]
P|1|110071393|188728|107040448|COSBANN~FRANCOISE~~~MLLE~||19450628|
F|||||||||||||||20071211~20071211||[NewLine]

but how to do for adding [CarriageReturn] ?

H|~^\&|8040200007||1~DXLAB||ORU|||2~SRA||P|H2.1|200804021123|

[CarriageReturn][NewLine]P|1|110071393|188728|107040448|
COSBANN~FRANCOISE~~~MLLE~||19450628|F|||||||||||||||20071211~20071211||
[CarriageReturn][NewLine]

Regards

Dale du Preez

unread,
Jan 14, 2010, 10:24:21 AM1/14/10
to ensemble-in...@googlegroups.com
Eric,

I can now see that the problem you have is extra <CR> characters, not
extra <CR,LF> pairs.

Why don't you try this instead?

set sourceLine = pInput.Read()
set pTa = $TRANSLATE(sourceLine,$C(13),"")

set pTa = $Replace(pTa, $C(10),$C(13,10))


//$$$LOGINFO("pTa "_pTa)
//Open 1 use 1 ZZDUMP pTa Close 1
set tSC = pTargetStream.Write(pTa)
set tSC = pTargetStream.%Save()

This should remove all $c(13) characters, and then convert all remaining
$c(10) characters to $c(13,10).

I hope that's what you are trying to do,
Dale

eric

unread,
Jan 14, 2010, 11:15:45 AM1/14/10
to InterSystems: Ensemble in Healthcare
Hi Dale,

With

set sourceLine = pInput.Read()
set pTa = $TRANSLATE(sourceLine,$C(13),"")
set pTa = $Replace(pTa, $C(10),$C(13,10))

$$$LOGINFO("pTa "_pTa)
//Open 1 use 1 ZZDUMP pTa Close 1
set tSC = pTargetStream.Write(pTa)
set tSC = pTargetStream.%Save()

the pTa is
pTa H|~^\&|8040200007||1~DXLAB||OR U|||2~SRA||P|H2.1|200804021123|
[CarriageReturn?][NewLine?] P|1|110071393|188728|107040448|
COSBANN~FRANCOISE~~~MLLE~||19450628|F|||||||||||||||
20071211~20071211||

but after i want t read all first line and all twice line to parse
them for example

while 'pTargetStream.AtEnd {
set tSubject=pTargetStream.ReadLine()
//set tSubject=pTargetStream.Read()
$$$LOGINFO("tSubject "_tSubject)
set typeSeg=$Piece(tSubject,"|",1)
}

and in this case i have

tSubject P|1|110071393|188728|107040448|COSBANN~FRANCOISE~~~MLLE~||
19450628|F|||||||||||||||20071211~20071211||
tSubject U|||2~SRA||P|H2.1|200804021123|
tSubject H|~^\&|8040200007||1~DXLAB||OR

i wanted
tSubject P|1|110071393|188728|107040448|COSBANN~FRANCOISE~~~MLLE~||
19450628|F|||||||||||||||20071211~20071211||
tSubject H|~^\&|8040200007||1~DXLAB||ORU|||2~SRA||P|H2.1|200804021123|

> >   set tSC = pTargetStream.%Save()- Masquer le texte des messages précédents -

Ted Peck

unread,
Jan 14, 2010, 11:32:16 AM1/14/10
to ensemble-in...@googlegroups.com
This is getting a bit tedious and it's very hard to follow because of the
email formatting and language issues.

Eric, do you think you could open a WRC case and ask our support advisers to
help you construct it exactly the way you want?

I think that would probably be faster and more effective than continuing
this email exchange.
Best regards,
Ted


----- Original Message -----
From: "eric" <eric.s...@alyotech.fr>
To: "InterSystems: Ensemble in Healthcare"
<Ensemble-in...@googlegroups.com>
Sent: Thursday, January 14, 2010 11:15 AM
Subject: [InterSystems-EnsHlth] Re: Remove Carriage Returns


Hi Dale,

With

--------------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages