Wednesday, 28 February 2018

Read text files that have line feed (LF) using X++

Here is an intrusting scenario, There was a task to read a csv file and do some xyz task. As we all developers know, it will work fine in Dev and when it comes to UAT, the actual scenario will come out.
The issue was, the file which they provided is with only Line Feed (LF) and hence it looks like below when opened in notepad.

we can see the line feed in the Notepad ++  as below.
As usual, the code did not work.  To fix this issue, I have added the below code

inputFile = new TextIo(@"c:\temp\Input.csv", 'R');
inputFile .inFieldDelimiter(',');
inputFile .inRecordDelimiter("\n");

which done the trick.

Note: If you have both line feed (LF) and carriage return (CR)
we can use inputFile .inRecordDelimiter("\r \n");



Removing Line Feed and Carriage Return from Strings

costCenter = strReplace(conPeek(_lineContainer, 17), '\n','');
 costCenter = strReplace(costCenter, '\r','');

No comments:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...