Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)
Answered

Insert line break in x++

Posted on by 280

Hi all

Running AX 2012 R3 CU9

Looking at an X++ method which I have that exports bill of exchange info to a text file at the moment. Basically it builds up a long string, and then exports that to the file.

eg:

outputTxt += strRFix(this.zipCode(), #ZipCode, '0');

.... (insert more here)

file.write(outputTxt);

However at a certain point, we have a business requirement to insert a carriage return on the line. I can't work out how to hardcode that. Is there a method which the X++ compiler will understand as Chr(13) or equivalent?

Thanks very much for your help in advance

Luke

*This post is locked for comments

  • Verified answer
    Sohaib Cheema Profile Picture
    Sohaib Cheema 46,610 User Group Leader on at
    RE: Insert line break in x++

    No I don't think so

    single \n will put new line. double backslash \\n will give you back \n in text. try following example in a job and you would know what I mean.

    str     myTestString;    
        myTestString += "InsertTestCodeHere\nAndTheLineBreakShouldGoThere";
        Box::info(myTestString);
        myTestString = '';
        myTestString += "InsertTestCodeHere\\n"+"AndTheLineBreakShouldGoThere";
        Box::info(myTestString);


  • lukbel Profile Picture
    lukbel 280 on at
    RE: Insert line break in x++

    Hi Sohaib,

    Basically what I would like to do is say, if I am hardcoding some text:

    outputTxt += "InsertTestCodeHere\nAndTheLineBreakShouldGoThere"

    But I was under the impression that the compiler would take that literally and insert the characters "\n"

    How can I tell it "put a carriage return here in the string"

  • Sohaib Cheema Profile Picture
    Sohaib Cheema 46,610 User Group Leader on at
    RE: Insert line break in x++

    Hi Lukbel,

    In AX char2Num converts chars and gives you back the ASCI number. It will be great if you can be more transparent in providing your requirement. For line break \n is used in most of languages, same follows the x++

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans