AX 2012 Development – Removing Line Feed and Carriage Return from Strings
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).
Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.
Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.