Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5967073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:53:27+00:00 2026-05-22T19:53:27+00:00

I am trying to read a text file using Dynamics AX. However, the following

  • 0

I am trying to read a text file using Dynamics AX. However, the following code replaces any spaces in the lines with commas:

// Open file for read access
myFile = new TextIo(fileName , 'R');

myFile.inFieldDelimiter('\n');

fileRecord = myFile.read();
while (fileRecord)
{
    line = con2str(fileRecord);
    info(line);
…

I have tried various combinations of the above code, including specifying a blank '' field delimiter, but with the same behaviour.

The following code works, but seems like there should be a better way to do this:

// 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);

The format of the file is field format. For example:

DATAFIELD1    DATAFIELD2  DATAFIELD3
DATAFIELD1                DATAFIELD3
DATAFIELD1    DATAFIELD2  DATAFIELD3

So what I end up with unless I use the workaround above is something like:

line=DATAFIELD1,DATAFIELD2,DATAFIELD3

The underlying problem here is that I have mixed input formats. Some of the files just have line feeds {LF} and others have {CR}{LF}. Using my workaround above seems to work for both. Is there a way to deal with both, or to strip \r from the file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:53:28+00:00Added an answer on May 22, 2026 at 7:53 pm

    Con2Str:

    Con2Str will retrieve a list of values from a container and by default uses comma (,) to separate the values.

    client server public static str Con2Str(container c, [str sep])
    

    If no value for the sep parameter is specified, the comma character will be inserted between elements in the returned string.

    Possible options:

    1. If you would like the space to be the default separator, you can pass space as the second parameter to the method Con2Str.

    2. One other option is that you can also loop through the container fileRecord to fetch the individual elements.

    Code snippet 1:

    Below code snippet loads the file contents into textbuffer and replace the carriage returns (\r) with new line (\n) character. The condition if (strlen(line) > 1) will help to skip empty strings due to the possible occurrence of consecutive newline characters.

    TextBuffer  textBuffer;
    str         textString;
    str         clearText;
    int         newLinePos;
    str         line;
    str         field1;
    str         field2;
    str         field3;
    counter     row;
    ;
    
    textBuffer  = new TextBuffer();
    textBuffer.fromFile(@"C:\temp\Input.txt");
    textString  = textBuffer.getText();
    clearText   = strreplace(textString, '\r', '\n');
    
    row = 0;
    while (strlen(clearText) > 0 )
    {
        row++;
        newLinePos  = strfind(clearText, '\n', 1, strlen(clearText));
        line        = (newLinePos == 0 ? clearText : substr(clearText, 1, newLinePos));
    
        if (strlen(line) > 1)
        {
            field1  = substr(line, 1, 14);
            field2  = substr(line, 15, 12);
            field3  = substr(line, 27, 10);
    
            info('Row ' + int2str(row) + ', Column 1: ' + field1);
            info('Row ' + int2str(row) + ', Column 2: ' + field2);
            info('Row ' + int2str(row) + ', Column 3: ' + field3);
        }
    
        clearText =  (newLinePos == 0 ? '' : substr(clearText, newLinePos + 1, strlen(clearText) - newLinePos));
    }
    

    Code snippet 2:

    You could use File macro instead of hard coding the values \r\n and R that denotes the read mode.

    TextIo      inputFile;
    container   fileRecord;
    str         line;
    str         field1;
    str         field2;
    str         field3;
    counter     row;
    ;
    
    inputFile = new TextIo(@"c:\temp\Input.txt", 'R');
    
    inputFile.inFieldDelimiter("\r\n");
    
    row = 0;
    while (inputFile.status() == IO_Status::Ok)
    {
        row++;
        fileRecord  = inputFile.read();
        line        = con2str(fileRecord);
    
        if (line != '')
        {
            field1  = substr(line, 1, 14);
            field2  = substr(line, 15, 12);
            field3  = substr(line, 27, 10);
    
            info('Row ' + int2str(row) + ', Column 1: ' + field1);
            info('Row ' + int2str(row) + ', Column 2: ' + field2);
            info('Row ' + int2str(row) + ', Column 3: ' + field3);
        }
    }
    

    Dynamics AX job output

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read the contents of a text file, in this case a
I am trying to read ASCII text response from a tcp open streaming socket
I am trying to read an XML-file from another server. However the the company
I'm currently trying to read in an XML file, make some minor changes (alter
I'm trying to read a .doc file into a database so that I can
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy
I am trying to read an Http response stream twice via the following: HttpWebResponse
I'm trying to read a file to produce a DOM Document, but the file
Possible Duplicate: Reading the last n lines from a huge text file I have
I'm trying to read through the documentation on Berkeley DB XML , and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.