Substituting string chars for beginners (was readln command)

        By now I should know better than to try to answer
programming questions on line while half asleep. As a penance
for newsgroup clutter, here is a full blown working program that
should work with any modern version of Pascal. (The original
Jensen and Wirth version does not contain "Length" or "String".)
        For beginning programmers, this simple program has
some useful features to use later. By using constants as
key parameters, you can easily modify these to do something
else. For example, it is an easy step up from here to make an
encryption program that is not very secure and step up from
that to one which is. Writing things you might use in other
programs as CONST, FUNCTION and PROCEDURE assignments makes
them easier to use again. Including a test example in any
interactive program saves you from having to type an entry
over and over until all the bugs are eliminated. Another thing
to include in the program (before debug is complete) is
substitute variables, which is the way "Dummy" is used here.
In this program if Dummy showed up with a string that did not
make sense, you still have "Entry" left to see if you entered
what you thought you did. Including an easy bail out from
interactive programs is fundamental. The bail out used here
is to press <Enter> by itself. I also like REPEAT...UNTIL
when going through all the worst case combinations I can think
of for an interactive program.

<clifp...@airmail.net>   1:39PM  10/7/95

###################### Program Begins

PROGRAM SubChar;
(* Substituting one character for another--Clif Penn 10/7/95 *)

CONST
ElimCh = '_' ;        SubCh  = ' ' ;

VAR
Entry, Dummy : STRING;

PROCEDURE Substitute(InCh, OutCh : CHAR; VAR s : STRING);
     VAR   p : INTEGER;
BEGIN
     FOR p := 1 TO Length(s) DO
         IF s[p] = OutCh THEN s[p] := InCh;
END;

BEGIN  (* main program *)
    WriteLn; WriteLn; WriteLn('THIS IS A TEST:');
    Dummy := 'The_quick_brown_fox_jumped_over_the_lazy_dogs_back.';
    WriteLn(Dummy);
    Substitute(SubCh, ElimCh, Dummy);
    Writeln(Dummy);

    WriteLn; WriteLn; WriteLn('ENTER NOTHING TO QUIT');
    REPEAT  (* until finished with program *)
        WriteLn('Enter a string with several " ', ElimCh, ' "s.');
        ReadLn(Entry);
        IF Length(Entry) = 0 THEN EXIT;
        Dummy := Entry ;
        Substitute(SubCh, ElimCh, Dummy);
        WriteLn(Dummy);
        Writeln;
    UNTIL Entry = ''  ;
END.