Sponsors
Search
Link to our site
Learning Resources
H OPTION(*NOSHOWCPY:*NOEXPDDS:*NODEBUGIO:*SRCSTMT:*SECLVL) H DFTACTGRP(*NO) ACTGRP(*NEW) CCSID(*CHAR : *JOBRUN) D TestName PR ExtPgm('STRIPCHR') D TextIn 250 D NbrofChars 3 0 D CharToStrip 1 D UpLow 1 D TestName PI D TextIn 250 D NbrofChars 3 0 D CharToStrip 1 D UpLow 1 D stripChars PR 250 Varying D instr 250 Value Varying D chars 1 Value Varying D zz S 3s 0 D pos S 10I 0 D workText s 250a D up c 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' D lo c 'abcdefghijklmnopqrstuvwxyz' /free If NbrOfChars > 0; workText = %subst(textIn:1:NbrOfChars); Else; workText = textIn; EndIf; If %parms() > 3; Select; When UpLow = 'L'; // Convert entire name string to lower case. workText = %xlate(up:lo:workText); When UpLow = 'U'; // Convert entire name string to upper case. workText = %xlate(lo:up:workText); Other; Endsl; EndIf; workText = stripChars(workText:CharToStrip); If NbrOfChars > 0 and NbrOfChars + 1 <= 250; textIn = %trimr(workText) + %subst(textIn:NbrOfChars + 1); Else; textIn = workText; EndIf; *Inlr = *On; /end-free //============================================================== // Procedure: stripChars //-------------------------------------------------------------- // Strip pre-defined characters from name field // // Parameters: // I: instr -- string to strip // I: chars -- character(s) to strip // // Returns: String of name with characters stripped. //===================================================== P stripChars B D stripChars PI 250 Varying D instr 250 Value Varying D char 1a Value Varying D workStr S 250a varying D outstr S Like(instr) D pos S 10I 0 /free pos = %scan(char:%trim(instr)); Dow pos > 0; instr = %replace('':instr:%scan(char:instr):1); pos = %scan(char:%trim(instr)); Enddo; outstr = %trim(instr); Return outstr; /end-free P stripChars E
[report a broken link by clicking here]