Anonymous user
CHANGESTR.REX: Difference between revisions
m
updated some comments in this version of the BIF. -- ~~~~
(added functionality to this version of the CHANGESTR function, changed comments, indentation. -- ~~~~) |
m (updated some comments in this version of the BIF. -- ~~~~) |
||
Line 1:
This version of the '''changestr''' BIF has more functionality than the standard BIF.
<lang rexx>/*REXX program emulates the CHANGESTR built-in function for older REXXes*/
/*──── This version has more functionality: limit the number of changes.*/
/*──── start of change
/*──── start of change position. */
/*╔══════════════════════════ CHANGESTR function ══════════════════════╗
╔═╩════════════════════════════════════════════════════════════════════╩═╗
║ The CHANGESTR function is used to replace some or all
║ (old) string in a haystack with a new string. The changed string is ║
║ returned. If the haystack doesn't contain the old string, the ║
Line 13 ⟶ 15:
║ ║
║ new string to be used►──────────┐ ┌─────◄limit of # changes (times).║
║ original string (haystack)►──────┐ │ │ [default: ≈ one
║ old string to be replaced►──┐ │ │ │ ┌────◄begin at this
║ {O, H, and N can be null.} │ │ │ │ │ ┌──◄start position (default=1)║
╚═╦════════════════════════════╗ │ │ │ │ │ │ ╔═════════════════════════╦═╝
Line 40 ⟶ 42:
h=substr(h,p) /*only use this part of H.*/
end /*now, proceed as usual. */
#=0 /*# of changed
do j=1 while # < t /*keep changing, T times. */
parse var h y (o) _ +(L) h /*parse the haystack ··· */
Line 46 ⟶ 48:
$=$ || y /*append the residual txt.*/
if j<b then $=$ || o /*append OLD if too soon. */
else do /*met the
$=$ || n /*append the NEW string.*/
#=#+1 /*bump
end
end /*j*/ /*Note: most REXX ··· */
/*
return f || $ || h /*
|