Replace Carriage return in CTL

Support/help with CloverETL (4.9) and CloverDX (5.0 or newer) implementation problems

tomapi
Posts: 4
Joined: Wed Jan 09, 2019 4:09 pm

Replace Carriage return in CTL

Postby tomapi » Thu Sep 03, 2020 9:17 am

Hello,

I would like to replace some content (N/A) finishing by a Carriage Return (\n) character but could not find out how. I've tried this function in CTL:
//#CTL2
string replaced_text;
// Transforms input record into output record.
function integer transform() {
replaced_text = $in.0.json_text;
replaced_text = replace(replaced_text, "\"N/A\n\"", "\"\"");
$out.0.json_text = replaced_text;
return ALL;
}

But my text isn't replaced. I guess "\n" should be treated specially but didn't find how.

Could you help me?

Thanks,

Thomas

jandikovae
Posts: 64
Joined: Fri Nov 04, 2016 8:51 am

Re: Replace Carriage return in CTL

Postby jandikovae » Mon Sep 14, 2020 9:01 pm

Hi Thomas,

As per my testing, the CTL2 code can handle the N/A text unchanged. However, I have at least used brackets to separate the text from the carriage return. Also, as you may have Carriage Returns but not Line Feeds in your input data, vice versa, or both, you can use the following expression, which will match any combination of those characters: [\r\n]. (The square brackets stands for OR operator). Then the desired CTL2 code would look as follows:

Code: Select all

replaced_text = $in.0.Field1;
replaced_text = replace(replaced_text,"(N/A)([\r\n])", "\"\"");
$out.0.Field1 = replaced_text;


Please give it a try and let me know if it works. If it doesn't work as you expected, could you please provide me with your input data so that I can take another look? Thanks and have a nice day, Eva.
---
Eva Jandikova
CloverCARE Support
CloverDX

Visit us online at http://www.cloverdx.com


cron