PROCEDURE REPLACE( SHORT : DSTRING; VAR LONG : DSTRING; idx : INTEGER); {++++++++++++++++++++++++++++++++++++++++++++++++} {+ REPLACE(Source, Destination, Index); +} {+ REPLACE(sub string, long string, idx); +} {++++++++++++++++++++++++++++++++++++++++++++++++} TYPE BYTE = 0..255; VAR K,K2,I, CharsToPlace, OVERFLOW: BYTE; BEGIN K := LENGTH(LONG); K2 := LENGTH(SHORT); IF ( (idx+K2) > K ) then begin { some chars of SHORT are beyond length of LONG. } OVERFLOW := (idx+K2) - (K+1); CharsToPlace := k2 - overflow; end else { the position of short is within long. } CharsToPlace := k2; for i:=1 to CharsToPlace do begin long[idx] := short[i]; idx := idx + 1; end; end(* of REPLACE *);  for i:=1 to CharsToPlace do begin long[idx] := short[i]; idx := idx + 1; end; end(