Focal Point
[SOLVED] Different behaviour than expected with CTRAN

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3857066096

August 08, 2018, 10:01 AM
ccollier
[SOLVED] Different behaviour than expected with CTRAN
I'm using CTRAN to replace a return (CR) and line feed (LF) with a null character.


 TABLE FILE MYTABLE
SUM
	COMPUTE CR/A2 = CTRAN(735, SENTENCE, 13, 0, CR);
	COMPUTE LF/A2 = CTRAN(735, SENTENCE, 10, 0, LF);
	COMPUTE TABLEDATA/A735 = '''' || REPLACE(SENTENCE, '''', '') || '''' ;
	COMPUTE TABLEDATA_NO_CR/A735 = REPLACE(TABLEDATA, CR, '');
	COMPUTE TABLEDATA_NO_LF_AND_CR/A735 = REPLACE(TABLEDATA, LF, ''); 
	BY SENTENCE NOPRINT
END
-RUN  



This code seems like it should work fine, but instead of replacing the characters I want, it replaces the first two letters of my sentence with a null character. I've tried to use the HEXBYT function, but got no results, so I figure that using this to get any result is better than none at all.

This message has been edited. Last edited by: ccollier,


WebFOCUS 8.2.01M on Windows 10
August 08, 2018, 10:31 AM
BabakNYC
If SENTENCE is an A735 field, you should change the format of CR and LF to A735 but if you're trying to create CR and LF fields you should try something like this:

  
CR/A1 = HEXBYT(13, 'A1');
LF/A1 = HEXBYT(10, 'A1');
CRLF/A2 = CR || LF;

This message has been edited. Last edited by: BabakNYC,


WebFOCUS 8206, Unix, Windows
August 08, 2018, 10:41 AM
ccollier
I'm computing them to make a variable to use. For some reason, there's an unwanted return and line feed character inside the sentence, so I'm computing both of them so I can use them inside the TABLEDATA_NO_CR and the TABLEDATA_NO_LF_AND_CR. From what I know, there's no way to call a replace on an ASCII character than by using CTRAN or HEXBYT to convert it into a character first, so I can call the variable in a REPLACE function later on.


WebFOCUS 8.2.01M on Windows 10
August 08, 2018, 11:14 AM
ccollier
As mentioned before, I tried to use HEXBYT, but it doesn't seem to have any effect on the data. When I try to replace CRLF with something I can see, for example a '?' it doesn't show up where a CR/LF should be.


WebFOCUS 8.2.01M on Windows 10
August 08, 2018, 11:17 AM
David Briars
-*
-* Function Name: REMOVECRLF
-* Purpose      : Take an A4000V alpha field and remove CRLF characters. Returns an A4000V.
-* Edit(s)      : 06/09/2015 - NBSP hex character now removed.
-*
DEFINE FUNCTION REMOVECRLF (IN4000/A4000V)
-* Remove 'apostrophe' characters.
 APOSSTRIPED/A4000V = STRREP(4000, IN4000,      2, (HEXBYT(146,'A1')), 1, '''', 4000, APOSSTRIPED);
-* Remove 'non-breaking space' characters.
 NBSPSTRIPED/A4000V = STRREP(4000, APOSSTRIPED, 2, (HEXBYT(160,'A1')), 1, ' ', 4000, NBSPSTRIPED);
-* Remove the CR.
 LINESTRIPED/A4000V = STRREP(4000, NBSPSTRIPED, 2, (HEXBYT(010,'A1')), 1, ' ', 4000, LINESTRIPED);
-* Remove the LF.
 REMOVECRLF/A4000V  = STRREP(4000, LINESTRIPED, 2, (HEXBYT(013,'A1')), 1, ' ', 4000, REMOVECRLF);
END  

Above is a DEFINE FUNCTION we use to clean up our text fields if/when required.

Sounds like you might want to look at the last two calcs?

This message has been edited. Last edited by: David Briars,
August 08, 2018, 11:22 AM
ccollier
Thank you very much David, that worked perfectly.


WebFOCUS 8.2.01M on Windows 10