new line '\n' replacement in #PRIM_TEXT or Field

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
gstenstrom
Posts: 17
Joined: Thu Feb 16, 2017 8:35 am

new line '\n' replacement in #PRIM_TEXT or Field

Post by gstenstrom » Thu Jun 15, 2017 1:41 am

I'm using #PRIM_TEXT for entry of notes. When the user enters a carriage return, a '\n' in sent to the our iSeries.
We then read these notes and strings them together with HTML Code in the HTML Container which doesn't recognizing the carriage return.
My problem is replacing the '\n' with '<br/>' .

.ReplaceAll doesn't work against #PRM_TEXT

So I tried it with my field before I send it to our iSeries.
#OC18_EmailHTML.ReplaceAll( '\\n' '<br>' ) and #OC18_EmailHTML.ReplaceAll( '\n' '<br>' ) doesn't work.

Any suggestions.

dannyoorburg
Posts: 156
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: new line '\n' replacement in #PRIM_TEXT or Field

Post by dannyoorburg » Thu Jun 15, 2017 6:25 am

Intrinsic functions never change their input, they just produce a result. Are you assigning the result back into the field? As in:

#OC18_EmailHTML := #OC18_EmailHTML.ReplaceAll( '\n' '<br>' )

Danny

MarkD
Posts: 625
Joined: Wed Dec 02, 2015 9:56 am

Re: new line '\n' replacement in #PRIM_TEXT or Field

Post by MarkD » Thu Jun 15, 2017 8:32 am

I am not sure if you mean "\n" literally, or as an escaped JavaScript representation of the newline character hex 0A?
In RDMLX the carriage return and line feed are often set up like this:

Define_Com Class(#prim_dc.UnicodeString) Name(#CarriageReturn)
Define_Com Class(#prim_dc.UnicodeString) Name(#LineFeed)

#CarriageReturn := (13).AsUnicodeString /* Hex 0D */
#LineFeed := (10).AsUnicodeString /* Hex 0A */

MarkD
Posts: 625
Joined: Wed Dec 02, 2015 9:56 am

Re: new line '\n' replacement in #PRIM_TEXT or Field

Post by MarkD » Fri Jun 16, 2017 8:50 am

If the data is on an iSeries (IBM i) and has already converted to EBCDIC then the CR and LF are not the same characters.

eg: https://www.ibm.com/support/knowledgece ... 003899.htm
In ASCII, newline is X'0A'. In EBCDIC, newline is X'15'. Windows programs normally use a carriage return followed by a line feed character at the end of each line of a text file. In ASCII, carriage return/line feed is X'0D'/X'0A'. In EBCDIC, carriage return/line feed is X'0D'/X'15'.

gstenstrom
Posts: 17
Joined: Thu Feb 16, 2017 8:35 am

Re: new line '\n' replacement in #PRIM_TEXT or Field

Post by gstenstrom » Sat Jun 17, 2017 2:18 am

Thanks for the help. This worked.

Code: Select all

Define Field(#sTemp) Reffld(#OC18_EmailHTML)
#CarriageReturn := (13).AsUnicodeString /* Hex 0D */
#LineFeed := (10).AsUnicodeString /* Hex 0A */

#sTemp := #ebNote
#OC18_EmailHTML := #sTemp.ReplaceAll( #LineFeed '<br>' )

Post Reply