1
{ ******************************************************************
3
****************************************************************** }
12
function LTrim(S : String) : String;
13
{ ------------------------------------------------------------------
14
Removes leading blanks
15
------------------------------------------------------------------ }
17
function RTrim(S : String) : String;
18
{ ------------------------------------------------------------------
19
Removes trailing blanks
20
------------------------------------------------------------------ }
22
function Trim(S : String) : String;
23
{ ------------------------------------------------------------------
24
Removes leading and trailing blanks
25
------------------------------------------------------------------ }
27
function StrChar(N : Byte; C : Char) : String;
28
{ ------------------------------------------------------------------
29
Returns a string made of character C repeated N times
30
------------------------------------------------------------------ }
32
function RFill(S : String; L : Byte) : String;
33
{ ------------------------------------------------------------------
34
Completes string S with trailing blanks for a total length L
35
------------------------------------------------------------------ }
37
function LFill(S : String; L : Byte) : String;
38
{ ------------------------------------------------------------------
39
Completes string S with leading blanks for a total length L
40
------------------------------------------------------------------ }
42
function CFill(S : String; L : Byte) : String;
43
{ ------------------------------------------------------------------
44
Completes string S with leading blanks
45
to center the string on a total length L
46
------------------------------------------------------------------ }
48
function Replace(S : String; C1, C2 : Char) : String;
49
{ ------------------------------------------------------------------
50
Replaces in string S all the occurences
51
of character C1 by character C2
52
------------------------------------------------------------------ }
54
function Extract(S : String; var Index : Byte; Delim : Char) : String;
55
{ ------------------------------------------------------------------
56
Extracts a field from a string. Index is the position of the first
57
character of the field. Delim is the character used to separate
58
fields (e.g. blank, comma or tabulation). Blanks immediately
59
following Delim are ignored. Index is updated to the position of
61
------------------------------------------------------------------ }
63
procedure Parse(S : String; Delim : Char; Field : PStrVector; var N : Byte);
64
{ ------------------------------------------------------------------
65
Parses a string into its constitutive fields. Delim is the field
66
separator. The number of fields is returned in N. The fields are
67
returned in Field^[0]..Field^[N - 1]. Field must be dimensioned in
69
------------------------------------------------------------------ }
71
procedure SetFormat(NumLength, MaxDec : Integer;
72
FloatPoint, NSZero : Boolean);
73
{ ------------------------------------------------------------------
74
Sets the numeric format
76
NumLength = Length of numeric field
77
MaxDec = Max. number of decimal places
78
FloatPoint = True for floating point notation
79
NSZero = True to write non significant zero's
80
------------------------------------------------------------------ }
82
function FloatStr(X : Float) : String;
83
{ ------------------------------------------------------------------
84
Converts a real to a string according to the numeric format
85
------------------------------------------------------------------ }
87
function IntStr(N : LongInt) : String;
88
{ ------------------------------------------------------------------
89
Converts an integer to a string
90
------------------------------------------------------------------ }
92
function CompStr(Z : Complex) : String;
93
{ ------------------------------------------------------------------
94
Converts a complex number to a string
95
------------------------------------------------------------------ }
100
gNumLength : Integer = 10;
101
gMaxDec : Integer = 4;
102
gFloatPoint : Boolean = False;
103
gNSZero : Boolean = False;
105
function LTrim(S : String) : String;
109
if S[1] = ' ' then Delete(S, 1, 1);
114
function RTrim(S : String) : String;
121
if S[L1] = ' ' then Delete(S, L1, 1);
126
function Trim(S : String) : String;
128
Trim := LTrim(RTrim(S));
131
function StrChar(N : Byte; C : Char) : String;
142
function RFill(S : String; L : Byte) : String;
150
RFill := S + StrChar(L - L1, ' ');
153
function LFill(S : String; L : Byte) : String;
161
LFill := StrChar(L - L1, ' ') + S;
164
function CFill(S : String; L : Byte) : String;
172
CFill := StrChar((L - L1) div 2, ' ') + S;
175
function Replace(S : String; C1, C2 : Char) : String;
190
function Extract(S : String; var Index : Byte; Delim : Char) : String;
198
while (I <= L) and (S[I] <> Delim) do
205
Extract := Copy(S, Index, I - Index);
207
{ Skip blanks after Delim }
210
until (I > L) or (S[I] <> ' ');
216
procedure Parse(S : String; Delim : Char; Field : PStrVector; var N : Byte);
224
Field^[I] := Extract(S, Index, Delim);
230
procedure SetFormat(NumLength, MaxDec : Integer;
231
FloatPoint, NSZero : Boolean);
233
if (NumLength >= 1) and (NumLength <= 80) then gNumLength := NumLength;
234
if (MaxDec >= 0) and (MaxDec <= 20) then gMaxDec := MaxDec;
236
gFloatPoint := FloatPoint;
240
function RemZero(S : String) : String;
255
if I = 0 then I := Pos('e', S);
259
S1 := Copy(S, 1, I - 1);
260
S2 := Copy(S, I, Length(S) - I + 1)
271
if (C = '0') or (C = '.') then S1 := Copy(S1, 1, I - 1)
277
function FloatStr(X : Float) : String;
283
Str(X:Pred(gNumLength), S);
287
Str(X:gNumLength:gMaxDec, S);
295
function IntStr(N : LongInt) : String;
299
Str(N:(gNumLength - gMaxDec - 1), S);
303
function CompStr(Z : Complex) : String;
307
if Z.Y >= 0.0 then S := ' + ' else S := ' - ';
308
CompStr := FloatStr(Z.X) + S + FloatStr(Abs(Z.Y)) + ' * i';