home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / morepscl.zip / MORESTRG.PAS < prev   
Pascal/Delphi Source File  |  1992-02-22  |  2KB  |  76 lines

  1. Uses CRT;
  2.  
  3. Function YesOrNo: Char;  {waits for an answer of Y or N. Needs CRT library}
  4.  Var CH: Char;
  5. Begin;
  6.  Repeat;
  7.   CH:=ReadKey;
  8.   CH:=UpCase(CH);
  9.  Until (CH = 'Y') or (CH = 'N');
  10.  YesOrNo:=CH;
  11. End;
  12.  
  13. Function Yes: Boolean;  {boolean version of YesOrNo. Needs CRT library}
  14.  Var CH: Char;
  15. Begin;
  16.  Repeat;
  17.   CH:=ReadKey;
  18.   CH:=UpCase(CH);
  19.  Until (CH='Y') or (CH='N');
  20.  Yes:=(CH='Y');
  21. End;
  22.  
  23. Function NumInStr(S: String): Boolean;
  24. {checks a string to see if it contains ONLY a numeric value}
  25.  VAR
  26.      C, I: INTEGER;
  27.         N: BOOLEAN;
  28.  
  29. BEGIN;
  30.  I:=0;
  31.  Repeat;
  32.   I:=I+1;
  33.   C:=Ord(S[I]);
  34.   N:=( (C >= 48) AND (C <= 57) );
  35.  Until (NOT N) OR (I=Length(S));
  36.  NumInStr:=N;
  37. END; {Number In String}
  38.  
  39. Function SubStr(S: String; X, Y: Integer): String;
  40.  { syntax: A:=SUBSTR(S,X,Y)
  41.    operates similarly to the COPY function, but 'Y' represents the
  42.    endpoint, not the length of the substring. This is the method that
  43.    FORTRAN and BASIC use for calling substrings.
  44.    ex.: Writeln(COPY('COMPUTER',2,5));
  45.         output: OMPUT
  46.         Writeln(SUBSTR('COMPUTER',2,5));
  47.         output: OMPU
  48.  }
  49.  
  50. Begin;
  51.  SubStr:=Copy(S,X,((Y-X)+1));
  52. End;
  53.  
  54. Procedure StrSwap(Var A, B: String);
  55.   Var C: String;
  56. Begin;
  57.   C:=A;
  58.   A:=B;
  59.   B:=C;
  60. End;
  61.  
  62. Function Left(X: STRING;  Y: INTEGER): STRING;
  63. {This is the equivalent of BASIC's LEFT$ function}
  64. BEGIN;
  65.   Left:=Copy(X,1,Y);
  66. END; {Left}
  67.  
  68. Function Right(X: STRING;  Y: INTEGER): STRING;
  69. {This is the equivalent of BASIC's RIGHT$ function}
  70.   VAR L: INTEGER;
  71. BEGIN;
  72.   L:=Length(X)-Y;
  73.   Right:=Copy(X,L+1,Y);
  74. END; {Right}
  75.  
  76.