title: How to read text files that have line feed and carriage return intermixed using X++?
body: <p>I am trying to read a text file using Dynamics AX. However, the following code replaces any spaces in the lines with commas:</p>
  
  <pre><code>// Open file for read access
  myFile = new TextIo(fileName , 'R');
  
  myFile.inFieldDelimiter('\n');
  
  fileRecord = myFile.read();
  while (fileRecord)
  {
      line = con2str(fileRecord);
      info(line);
  …
  </code></pre>
  
  <p>I have tried various combinations of the above code, including specifying a blank <code>''</code> field delimiter, but with the same behaviour.</p>
  
  <p>The following code works, but seems like there should be a better way to do this:</p>
  
  <pre><code>// Open file for read access
  myFile = new TextIo(fileName , 'R');
  
  myFile.inRecordDelimiter('\n');
  myFile.inFieldDelimiter('_stringnotinfile_');
  
  fileRecord = myFile.read();
  while (fileRecord)
  {
      line = con2str(fileRecord);
      info(line);
  </code></pre>
  
  <p>The format of the file is field format.  For example:</p>
  
  <pre><code>DATAFIELD1    DATAFIELD2  DATAFIELD3
  DATAFIELD1                DATAFIELD3
  DATAFIELD1    DATAFIELD2  DATAFIELD3
  </code></pre>
  
  <p>So what I end up with unless I use the workaround above is something like:</p>
  
  <pre><code>line=DATAFIELD1,DATAFIELD2,DATAFIELD3
  </code></pre>
  
  <p>The underlying problem here is that I have mixed input formats. Some of the files just have line feeds <code>{LF}</code> and others have <code>{CR}{LF}</code>. Using my workaround above seems to work for both. Is there a way to deal with both, or to strip <strong><code>\r</code></strong> from the file?</p>