home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / tplib21.zip / INSTALL.EXE / EXSTR.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  7KB  |  194 lines

  1. (* Example program: STRINGS unit *)
  2.  
  3. PROGRAM EXSTR;
  4.  
  5. USES 
  6.     STRINGS;
  7.  
  8. VAR
  9.     s,s1,s2,s3:  STRING;
  10.  
  11.  
  12. PROCEDURE ExOpt1;
  13.  
  14.     BEGIN
  15.         WriteLn('Try entering different strings at the prompt and observe');
  16.         WriteLn('effect of each function.  For this demonstration the width');
  17.         WriteLn('parameter passed to each function except TrimL and TrimR is');
  18.         WriteLn('always 8.  Enter "Q" to exit.');
  19.         REPEAT
  20.             WriteLn;
  21.             Write('Enter string : ');
  22.             ReadLn(s);
  23.             IF UpperCase(s)='Q' THEN EXIT;
  24.             WriteLn;
  25.             WriteLn('Source string = "', s, '"');
  26.             WriteLn('TrimL (s)     = "', TrimL(s),'"');
  27.             WriteLn('TrimR (s)     = "', TrimR(s),'"');
  28.             WriteLn('PadL  (s,8)   = "', PadL(s,8),'"');
  29.             WriteLn('PadR  (s,8)   = "', PadR(s,8),'"');
  30.             WriteLn('TruncL(s,8)   = "', TruncL(s,8),'"');
  31.             WriteLn('TruncR(s,8)   = "', TruncR(s,8),'"');
  32.             WriteLn('JustL (s,8)   = "', JustL(s,8),'"');
  33.             WriteLn('JustR (s,8)   = "', JustR(s,8),'"');
  34.             WriteLn('JustC (s,8)   = "', JustC(s,8),'"');
  35.             WriteLn;
  36.         UNTIL FALSE;
  37.     END;  { ExOpt1 }
  38.  
  39.  
  40. PROCEDURE ExOpt2;
  41.  
  42.     BEGIN
  43.         WriteLn('Try entering different strings at the prompts and observe');
  44.         WriteLn('the effect of each function.  Enter "Q" to exit.');
  45.         WriteLn;
  46.         REPEAT
  47.             WriteLn;
  48.             Write ('Enter string : ');
  49.             ReadLn(s1);
  50.             IF UpperCase(s1)='Q' THEN EXIT;
  51.             Write ('Enter target : ');
  52.             ReadLn(s2);
  53.             WriteLn;
  54.             WriteLn ('Source string = "', s1, '"');
  55.             WriteLn ('Target string = "', s2, '"');
  56.             WriteLn ('Precede(s1,s2) = "', Precede(s1,s2),'"');
  57.             WriteLn ('Follow(s1,s2) = "', Follow(s1,s2),'"');
  58.             WriteLn;
  59.         UNTIL FALSE;
  60.     END;  { ExOpt2 }
  61.  
  62.  
  63. PROCEDURE ExOpt3;
  64.  
  65.     BEGIN
  66.         WriteLn('Break and Span emulate the functions of the same name found');
  67.         WriteLn('in the SNOBOL programming language.  For this demonstration');
  68.         WriteLn('assume that a list of numbers must be parsed and broken');
  69.         WriteLn('down into separate elements.  Enter a string of numbers, ');
  70.         WriteLn('separating them with a random assortment of any other');
  71.         WriteLn('characters, including spaces, commas, semi-colons, and even');
  72.         WriteLn('alphabetic characters.  Press RETURN to see how each');
  73.         WriteLn('call to Break and Span changes the strings involved.');
  74.         WriteLn('Break is used to remove punctuation and Span is used to ');
  75.         WriteLn('extract the individual numbers.');
  76.         WriteLn;
  77.         Write('Enter string : ');
  78.         ReadLn(s);
  79.         REPEAT
  80.             WriteLn;
  81.             WriteLn ('Break (s, DecDigits) = "', Break (s, DecDigits), '"');
  82.             WriteLn ('Break has changed s to "', s, '"');
  83.             Write('Press RETURN to continue...');
  84.             ReadLn(s1);
  85.             WriteLn;
  86.             WriteLn ('Span (s, DecDigits) = "', Span (s, DecDigits), '"');
  87.             WriteLn ('Span has changed s to "', s, '"');
  88.             Write('Press RETURN to continue...');
  89.             ReadLn(s1);
  90.         UNTIL s='';
  91.     END; { ExOpt3 }
  92.  
  93.  
  94. PROCEDURE ExOpt4;
  95.  
  96.     BEGIN
  97.         WriteLn('At each prompt enter a string to work on, a search string,');
  98.         WriteLn('and the replacement string.  Remove uses only the search');
  99.         WriteLn('string to strip all matching characters.  Replace');
  100.         WriteLn('substitutes a character from the replacement string, repl.');
  101.         WriteLn('Enter string as "Q" to exit.');
  102.         REPEAT
  103.           WriteLn;
  104.           Write('Enter string : ');
  105.           ReadLn(s1);
  106.           IF UpperCase(s1)='Q' THEN EXIT;
  107.           Write ('Enter Srch   : ');
  108.           ReadLn(s2);
  109.           Write('Enter Repl   : ');
  110.           ReadLn(s3);
  111.           WriteLn;
  112.           WriteLn('Searching the string "', s1, '"');
  113.           WriteLn('for any of the characters in "', s2, '"');
  114.           WriteLn('Remove (s, Srch)        = "', Remove(s1,s2), '"');
  115.           WriteLn('Replace (s, Srch, Repl) = "', Replace(s1,s2,s3), '"');
  116.         UNTIL FALSE;
  117.     END;  { ExOpt4 }
  118.  
  119.  
  120. PROCEDURE ExOpt5;
  121.  
  122.     BEGIN
  123.       WriteLn('Assume that the following strings are passed as parameters:');
  124.       WriteLn;
  125.       WriteLn('path = ''C:\PATH\''   name = ''FILENAME''  extn = ''.EXT''');
  126.       WriteLn;
  127.       WriteLn('Try entering different path and filenames, sometimes omitting');
  128.       WriteLn('one or more sections.  Enter "Q" to exit.');
  129.       REPEAT
  130.         WriteLn;
  131.         Write ('Enter string : ');
  132.         ReadLn(s1);
  133.         IF UpperCase(s1)='Q' THEN EXIT;
  134.         WriteLn;
  135.         WriteLn('Supplied string                       = "', s1, '"');
  136.         WriteLn('FileSpecDefault (s, path, name, extn) = "',
  137.                  FileSpecDefault (s1, 'C:\PATH\', 'FILENAME', '.EXT'), '"');
  138.       UNTIL FALSE;
  139.     END; { ExOpt5 }
  140.  
  141.  
  142. PROCEDURE ExOpt6;
  143.  
  144.     BEGIN
  145.       WriteLn('Try entering different format control strings at each prompt.');
  146.       WriteLn('For each string you enter a sample of output for different');
  147.       WriteLn('values will be shown.  Enter "Q" to exit.');
  148.       REPEAT
  149.         WriteLn;
  150.         Write('Enter format string : ');
  151.         ReadLn(s);
  152.         IF UpperCase(s)='Q' THEN EXIT;
  153.         WriteLn;
  154.         WriteLn('Input value of:               Gives a result of:');
  155.         WriteLn('    50                        "', Format (50,s), '"');
  156.         WriteLn('   -35                        "', Format (-35,s), '"');
  157.         WriteLn(' 2,490                        "', Format (2490,s), '"');
  158.         WriteLn('    47.26                     "', Format (47.26,s), '"');
  159.         WriteLn('  -503.9621                   "', Format (-503.9621,s), '"');
  160.         WriteLn('     0                        "', Format (0,s), '"');
  161.       UNTIL FALSE;
  162.     END;  { ExOpt6 }
  163.  
  164.  
  165. BEGIN  { ExStr }
  166.     WriteLn('EXSTR - STRINGS UNIT EXAMPLE PROGRAM');
  167.     WriteLn;
  168.     REPEAT
  169.         WriteLn;
  170.         WriteLn('Select the features you wish to try:');
  171.         WriteLn;
  172.         WriteLn('    1.  Trim, pad, truncate, and justify.');
  173.         WriteLn('    2.  Precede & Follow.');
  174.         WriteLn('    3.  Break & Span.');
  175.         WriteLn('    4.  Replace, Remove.');
  176.         WriteLn('    5.  FileSpecDefault.');
  177.         WriteLn('    6.  Format');
  178.         WriteLn;
  179.         Write('Enter option or zero to quit : ');
  180.         ReadLn(s);
  181.         s:=TrimL(s);
  182.         WriteLn;
  183.         CASE s[1] OF
  184.             '1':    ExOpt1;
  185.             '2':    ExOpt2;
  186.             '3':    ExOpt3;
  187.             '4':    ExOpt4;
  188.             '5':    ExOpt5;
  189.             '6':    ExOpt6;
  190.         END;
  191.     UNTIL s[1]='0';
  192. END.
  193.  
  194.