bvstone

Removing Trailing Carriage Returns and/or Line Feeds from a String with RPG

Posted:

Removing Trailing Carriage Returns and/or Line Feeds from a String with RPG

I have an in house application that reads information from a web screen using RPG.  A couple fields are using Text Areas in the HTML, and for some reason I was getting extra carriage return and line feed characters in the text.

After debugging the program, I assumed they were just coming from reading the web page itself.  So I wanted to strip them off.  But, they were coming in as:

Text[CRLF][LF]

So, if you hit enter at the end of the text, you would get a CRLF followed by another LF.  

There are also places in this text where I do want to retain the CRLF in the text, but not at the end as when displaying the information it adds extra whitespace to the display.

My first thought was use the %trimr BIF specifying a character of x'0D25' to trim.  But this didn't work since in all actuality the last trailing characters are blanks, then CRLF/LF characters before the blanks.  Similar to this:

This is a string[CRLF][LF][Blanks......]

So I thought, if I trim the blanks, then the LFs, then the CRLFs, all in one embedded statement, things should work out fine.  What I ended up with was this:

DATA = %trimr(%trimr(%trimr(DATA):x'25'):x'0D25');  

This not only takes care of any CRLFLF strings that are added when Enter is pressed onces, but if the user also presses enter more than once it will also remove any extra trailing CRLFs that are added before the last LF.

Once I knew this worked in my processing program, I wrote a simple program to read through all the records and remove any remaining CRLF/LF trailing data and my OCD was happy again not to have extra white space at the end of the records displayed in my online application!


Last edited 12/26/2018 at 11:44:35



Latest Posts:

G4MSDRV Currently Not Supported G4MSDRV Currently Not Supported
Posted by 3 days ago
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
Removing Trailing Carriage Returns and/or Line Feeds from a String with RPG Removing Trailing Carriage Returns and/or Line Feeds from a String with RPG
Posted by December 26, 2018
Programming >> RPG Programming
Create QRCODE in DDS Create QRCODE in DDS
Posted by September 21, 2018
Programming >> RPG Programming
Base64 Encoding a File with RPG Base64 Encoding a File with RPG
Posted by September 6, 2018
Programming >> RPG Programming
Building JSON with RPG and YAJL and Writing to Standard Output Building JSON with RPG and YAJL and Writing to Standard Output
Posted by August 31, 2018
Programming >> Proof of Concept (POC)
How to Delete Files or Empty Trash From Your Google Drive with your IBM i and RPG/ILE How to Delete Files or Empty Trash From Your Google Drive with your IBM i and RPG/ILE
Posted by July 24, 2018
BVSTools >> BVSTools Software Discussion >> GreenTools for G Suite (Google Apps) (G4G) Specific Discussion
GreenTools for G Suite (G4G) Updated to Include Delete and Empty Trash Function GreenTools for G Suite (G4G) Updated to Include Delete and Empty Trash Function
Posted by July 24, 2018
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
What to Do If Your License Keys Don't Work What to Do If Your License Keys Don't Work
Posted by July 18, 2018
BVSTools >> BVSTools Software Discussion
MAILTOOL Updated to Allow Failed Message on Invalid Recipient MAILTOOL Updated to Allow Failed Message on Invalid Recipient
Posted by May 20, 2018
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
Non HTTPS Callbacks Removed from GreenTools for G Suite (G4G) Non HTTPS Callbacks Removed from GreenTools for G Suite (G4G)
Posted by April 15, 2018
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
IBM i Related Survey Available IBM i Related Survey Available
Posted by April 7, 2018
IBM Power Systems >> (QGPL) IBM i
BVSTools Releases Braintree Webhook Open Source Application - Node.js BVSTools Releases Braintree Webhook Open Source Application - Node.js
Posted by April 5, 2018
Programming >> Open Source
BVSTools Now Offering Web Services (BETA) BVSTools Now Offering Web Services (BETA)
Posted by April 3, 2018
BVSTools >> BVSTools Announcements
Creating a Reverse SSL Proxy Using RPG on the IBM i - Part 2 Creating a Reverse SSL Proxy Using RPG on the IBM i - Part 2
Posted by March 29, 2018
Programming >> Web Programming
Still on V7R1 or Earlier?  Here's Why You Should Upgrade NOW! Still on V7R1 or Earlier? Here's Why You Should Upgrade NOW!
Posted by February 21, 2018
IBM Power Systems >> (QGPL) IBM i

Reply




Copyright 1983-2018 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).