
Return to the RPG Tips
BIF to trim leading 0's or any character
P Strip b
D Strip pi 256a varying
D string 256a const varying
D char 256a const varying options(*nopass)
D i s 10i 0
D ch s 256a varying inz('0')
/free
// default to '0' if second parm not specified
if %parms >= 2;
ch = char;
endif;
// locate first char not equal to strip char
i = %check(ch:string);
if i = 0;
return '';
endif;
return %subst(string:i);
/end-free
P Strip e
By default, this strips leading zeros. But if you specify an
optional second parameter to the procedure, you can strip off any
other characters you want.
Although this is written using the new V5R1 syntax, (and compiled and tested on a V5R1 machine) this should be easy to rewite to run on a V4R4 system.
Examples of use:
Strip('0000123') ===> '123'
Strip('****456':'*') ===> '456'
Strip('$***456':'*$') ===> '456'
Cheers! Hans[report a broken link by clicking here]






