Board index » delphi » Substituting string chars for beginners (was readln command)
clifp...@airmail.net (CLIF PENN)
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
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; CONST VAR PROCEDURE Substitute(InCh, OutCh : CHAR; VAR s : STRING); BEGIN (* main program *) WriteLn; WriteLn; WriteLn('ENTER NOTHING TO QUIT'); |