Showing posts with label new line character. Show all posts
Showing posts with label new line character. Show all posts

Wednesday, March 16, 2022

D365 - removing new line character from string (note/memo/text) fields

I wrote a post about how to do this in AX 2009, but D365 has made it much easier with the global method strReplace().

It accepts a string, fromStr, toStr and returns the changed string.

So to clear out new line characters:

string StringwithNewline;

stringwithnewline = strReplace(stringwithNewLine,'\n',' ');

This will replace new line characters with a space.

Wednesday, August 17, 2011

Dynamics AX 2009 - removing new line character from string (note/memo/text) fields

So this is my first post on this dynamics AX blog of mine. I'm going to use this to keep track of the little programming solutions I develop. Maybe it will help someone else too. Who knows?

My customer was having problems with a report showing the delivery address in excel. When a new line character is reached, it moves to another line. This made the excel format untenable for our 3rd party vendor that needed the data. So I wrote this code on the report to strip the new line character out and replace it with a space.

display str DeliveryStreet()
{
TextBuffer txt = new TextBuffer();
;

txt.setText(dataSource.DeliveryStreet);
txt.replace('\n',' ');
dataSource.DeliveryStreet = txt.getText();

return(dataSource.DeliveryStreet);
}

The DeliveryStreet field on the report calls this method instead of calling the field on the datasource.