home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
On Disk Monthly 62
/
odm62.zip
/
GDSOURCE.EXE
/
STRINGS.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-10-14
|
4KB
|
165 lines
unit strings;
interface
{$F+}
FUNCTION StrI(I: integer): string;
FUNCTION StrIF(I: integer; Field: integer): string;
FUNCTION StrL(L: longint): string;
FUNCTION StrLF(L: longint; Field: integer): string;
FUNCTION StrR(R: real): string;
FUNCTION StrRF(R: real; Field: integer): string;
FUNCTION StrRFD(R: real; Field, Decimals: integer): string;
FUNCTION UpperCase(S : string): string;
FUNCTION LowerCase(S : string): string;
FUNCTION StringOf(C : char; StringLength : byte): string;
FUNCTION StripChar(S : string; C : char): string;
FUNCTION PadSpaces(S : string; StringLength : byte): string;
FUNCTION LeftPad(S : string; C : char; StringLength : byte): string;
FUNCTION CenterPad(S : string; C : char; StringLength : byte): string;
FUNCTION RightPad(S : string; C : char; StringLength : byte): string;
implementation
FUNCTION StrI(I: integer): string;
VAR StrResult: ^string;
BEGIN
Inline( $89/$EC/$16/$FF/$76/$08);
Str(I, StrResult^);
END;
FUNCTION StrIF(I: integer; Field: integer): string;
VAR StrResult: ^string;
BEGIN
Inline($89/$EC/$16/$FF/$76/$0A);
Str(I:Field, StrResult^);
END;
FUNCTION StrL(L: longint): string;
VAR StrResult: ^string;
BEGIN
Inline($89/$EC/$16/$FF/$76/$0A);
Str(L, StrResult^);
END;
FUNCTION StrLF(L: longint; Field: integer): string;
VAR StrResult: ^string;
BEGIN
Inline($89/$EC/$16/$FF/$76/$0C);
Str(L:Field, StrResult^);
END;
FUNCTION StrR(R: real): string;
VAR StrResult: ^string;
BEGIN
Inline($89/$EC/$16/$FF/$76/$0C);
Str(R, StrResult^);
END;
FUNCTION StrRF(R: real; Field: integer): string;
VAR StrResult: ^string;
BEGIN
Inline($89/$EC/$16/$FF/$76/$0E);
Str(R:Field, StrResult^);
END;
FUNCTION StrRFD(R: real; Field, Decimals: integer): string;
VAR StrResult: ^string;
BEGIN
Inline($89/$EC/$16/$FF/$76/$10);
Str(R:Field:Decimals, StrResult^);
END;
{$F-}
FUNCTION UpperCase(S : string): string;
VAR I : byte;
BEGIN
FOR I := 1 TO Length(S) DO
S[I] := UpCase(S[I]);
UpperCase := S;
END;
FUNCTION LowerCase(S : string): string;
VAR I : byte;
BEGIN
FOR I := 1 TO Length(S) DO
IF (S[I] >= 'A') AND (S[I] <= 'Z') THEN
S[I] := Chr(Ord(UpCase(S[I])) + 32);
LowerCase := S;
END;
FUNCTION StringOf(C : char; StringLength : byte): string;
VAR I : byte;
BEGIN
FOR I := 1 TO StringLength DO
StringOf[I] := C;
StringOf[0] := Chr(StringLength);
END;
FUNCTION StripChar(S : string; C: char): string;
VAR I : byte;
L : byte;
BEGIN
L := 1;
FOR I := 1 TO Length(S) DO
BEGIN
IF S[I] <> C THEN
BEGIN
StripChar[L] := S[I];
inc(L);
END;
END;
StripChar[0] := Chr(Pred(L));
END;
FUNCTION PadSpaces(S : string; StringLength : byte): string;
VAR I : byte;
L : byte;
BEGIN
L := Length(S);
IF L > StringLength THEN
L := StringLength;
PadSpaces := Copy(S, 1, L) + StringOf(' ', StringLength - L)
END;
FUNCTION LeftPad(S : string; C : char; StringLength : byte): string;
VAR I : byte;
L : byte;
BEGIN
L := Length(S);
IF L > StringLength THEN
L := StringLength;
LeftPad := Copy(S, 1, L) + StringOf(C, StringLength - L);
END;
FUNCTION CenterPad(S : string; C : char; StringLength : byte): string;
VAR I : byte;
L : byte;
BEGIN
L := (StringLength - Length(S)) shr 1;
IF L > 128 THEN
BEGIN
L := 0;
I := StringLength;
END
ELSE
I := Length(S);
CenterPad := StringOf(C, L) + Copy(S, 1, I) + StringOf(C, StringLength - I - L);
END;
FUNCTION RightPad(S : string; C : char; StringLength : byte): string;
VAR I : byte;
L : byte;
BEGIN
L := StringLength - Length(S);
I := 1;
IF L > 128 THEN
BEGIN
L := 0;
I := Length(S) - StringLength + 1;
END;
RightPad := StringOf(C, L) + Copy(S, I, StringLength);
END;
END.