Strip Formatting

From MidrangeWiki
Revision as of 20:22, 12 December 2018 by DaveLClarkI (talk | contribs) (Created page with "//============================================================================== // Strip all occurrences of the specified delimiter(s) from a string -- // including emb...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

//============================================================================== // Strip all occurrences of the specified delimiter(s) from a string -- // including embedded occurrences of those delimiters. If delimiters // are omitted, then all blanks are stripped by default. //============================================================================== dcl-pr GenUtl_StripFormatting varchar(512) rtnparm;

 StringValue           varchar(512)   const;
 DelimsValue           varchar(64)    const     options(*omit);

end-pr;

//============================================================================== // Strip all occurrences of the specified delimiter(s) from a string -- // including embedded occurrences of those delimiters. If delimiters // are omitted, then all blanks are stripped by default. //============================================================================== dcl-proc GenUtl_StripFormatting export;

 dcl-pi *n             varchar(512)   rtnparm;
   StringValue         varchar(512)   const;
   DelimsValue         varchar(64)    const     options(*omit);
 end-pi;
 dcl-s x               packed(3:0);
 dcl-s OutputString    like(StringValue);
 if %parms() < %parmnum(DelimsValue); // if omitted strip all blanks by default
   OutputString = GenUtl_ScanAndReplace(' ': %trim(StringValue): );
 else;
   OutputString = %trimr(StringValue); // else, strip only trailing blanks
   for x = 1 to %len(DelimsValue);    // loop on formatting characters
     OutputString = GenUtl_ScanAndReplace( %subst(DelimsValue: x: 1)
                                         : OutputString:  );
   endfor;
 endif;
 return OutputString;                 // return result string to caller

end-proc;