home *** CD-ROM | disk | FTP | other *** search
- Unit DFStr;
-
- { ----------------------------------------------------------------------
- DFSTR.PAS - string functions for Turbo Pascal
-
- Written 1991 by:
-
- David Firth GEnie: D.FIRTH
- 5665 A2 Parkville Ct. CIS: 76467,1734
- Columbus, OH 43229
- (614) 523-1968
-
- Revision 0: May 1991 - __JustStr & __RemWhiteStr for TP3
- Revision 1: Dec 1991 - Made file into a unit for TP5 or above
-
- ---------------------------------------------------------------------- }
-
- Interface
-
- Type
-
- Str8 = string[8];
-
- Const
-
- _LeftJustify : byte = 0; {__JustStr}
- _RightJustify : byte = 1; {__JustStr}
- _Leading : byte = 0; {__RemWhiteStr}
- _Trailing : byte = 1; {__RemWhiteStr}
- _All : byte = 2; {__RemWhiteStr}
-
- Function __RemWhiteStr(InputStr:string;MyMode:byte):string;
-
- Function __JustStr(InputStr:string;
- Len:byte;
- JustChar:char;
- JustMode:byte) : string;
-
- Implementation
-
- { ------------------------ PROCEDURES/FUNCTIONS ----------------------- }
-
- Function __JustStr(InputStr:string;
- Len:byte;
- JustChar:char;
- JustMode:byte) : string;
-
- { Justify string is a very useful function for padding strings. After
- the first time I used a justify function, I had to hae one for TP3.
-
- InputStr is the string to pad.
-
- Len is the length that the final string needs to be.
-
- JustChar is the character to pad by.
-
- JustMode is a constant, chosen from the list above, which chooses
- whether the string is left or right justified.
- }
-
- Var
-
- Count, {general purpose counter }
- NumChars : byte; {number of characters to pad with}
-
- Begin
-
- if Length(InputStr) < Len then begin
-
- NumChars := Len - Length(InputStr);
- for Count := 1 to NumChars do begin
- case JustMode of
- 0: InputStr := InputStr + JustChar;
- 1: InputStr := JustChar + InputStr;
- end; {case}
- end; {for}
-
- end
- else begin
-
- InputStr := Copy(InputStr,1,Len);
-
- end; {if-else}
-
- __JustStr := InputStr;
-
- End; {__JustStr}
-
- { --------------------------------------------------------------------- }
-
- Function __RemWhiteStr(InputStr:string;MyMode:byte):string;
-
- { This function is useful for stripping spaces from a string.
-
- InputStr is the string that will be processed.
-
- MyMode is a constant, chosen from the list above, that chooses
- whether the leading, trailing, or entire complement of spaces
- is removed.
- }
-
- Var
-
- Count : byte; {general purpose counter}
- MyStr : string; {temporary string }
-
- begin
-
- if (MyMode=_Leading) then begin
- {remove the leading spaces}
- Count := 0;
- while (InputStr[Count+1]=' ') AND (Count<Length(InputStr)) do begin
- Count := Count + 1;
- end; {while}
- if Count > 0 then
- Delete(InputStr,1,Count);
- end; {if}
-
- if (MyMode=_Trailing) then begin
- {remove the leading spaces}
- Count := Length(InputStr);
- while (InputStr[Count]=' ') AND (Count>0) do begin
- Count := Count - 1;
- end; {while}
- if Count < Length(InputStr) then
- Delete(InputStr,Count+1,Length(InputStr)-Count);
- end; {if}
-
- if (MyMode=_All) then begin
- MyStr := '';
- for Count := 1 to Length(InputStr) do begin
- if InputStr[Count] <> ' ' then
- MyStr := MyStr + InputStr[Count];
- end; {for}
- InputStr := MyStr;
- end; {if}
-
- __RemWhiteStr := InputStr;
-
- end; {__RemWhiteStr}
-
- { --------------------------------------------------------------------- }
-
- end. {unit}
-