AX 2012 Development – Removing Line Feed and Carriage Return from Strings

By Sourabh Khosla | August 8, 2014

Before I go ahead and explain the code for removing Line Feed and Carriage Return in Dynamics AX, lets discuss what's the actual difference between these two?

Line Feed – LF – \n – 0x0a – 10 (decimal)
Carriage Return – CR – \r – 0x0D – 13 (decimal)

As different operating systems have a different way of understanding new line, we have two different new line characters. This actually dates back to the two axes of motion for typewriters, but we won't go into that much detail.
Windows operating system uses both the characters together to interpret as new line, which is ‘\r\n’ and Mac only understands ‘\r’ as new line, while Unix and Linux understand ‘\n’ as new line character.

Now, getting back to X++ point of view.

strReplace(originalString, '\n', '');

strReplace(originalString, '\r', '');

We would need to use both of these statements since we want remove every possibility that the LF/CF are removed and it is going to work in all the OS's. The reason I am being cautious about such a situation is if you are using X++ to create Excel/Notepad files you want to make sure that the file opens with the same line spacing in all OS's (be it Linux/Windows or Mac).

Related Posts

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!