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.
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:
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.