Use Notepad ++’s find and replace! …
Since Notepad++ has no relevance to the question, I’m replacing almost all of the previous “Answer”.
The real answer is to stop allowing invalid characters from being accepted at the point of entry. If you would simply validate the input properly, it would never get into the PF in the first place. Failure to validate input can conceivably be grounds for termination under various circumstances.
In RPG, use the %xlate() BIF:<pre>
string = %XLATE( invalid : valid : InputString );</pre>
Create a variable named INVALID (or a name of your choice) that contains all characters that you consider to be invalid. Create another variable named VALID (or whatever) that contains the characters you want in place of each invalid character. If you are scanning a field named InputString, the result will be placed in the field named string.
If a carriage return (x’0D’) is the only character that you’re concerned about, the statement might simply be:<pre>
string = %XLATE( x’0D’ : ‘ ‘ : InputString );</pre>
The carriage returns will be replaced by spaces.
You can do similarly with SQL using the TRANSLATE() function. In COBOL, use INSPECT … REPLACING. In CL, call QDCXLATE. (Any other language can also do that call.).
ILE languages can also call the XLATEB MI builtin function. One advantage for RPG, for example, is that the translation occurs directly in the source variable. This might be the most flexible of the various methods here. It accepts addresses of variables and translates based on a length parameter. Any number of different variables can be handled by the same procedure without any data movement.