-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNumStr.pas
178 lines (162 loc) · 3.57 KB
/
NumStr.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
unit NumStr;
{$S-,R-,V-}
interface
Function WordCnt(Str:string):byte;
Function ExtractWords(StartWord,NoWords:byte;Str:string):string;
Function LocWord(StartAT,Wordno:byte;Str:string):byte;
function BFromStr(var Value: byte; const S: string;
const Pos, Len: integer): boolean;
function WFromStr(var Value: word; const S: string;
const Pos, Len: integer): boolean;
function IFromStr(var Value: integer; const S: string;
const Pos, Len: integer): boolean;
function SFromStr(var Value: single; const S: string;
const Pos, Len: integer): boolean;
function DFromStr(var Value: double; const S: string;
const Pos, Len: integer): boolean;
implementation
uses SysUtils, Dialogs;
var
Code: integer;
Function WordCnt(Str:string):byte;
var
W,I: integer;
SpaceBefore: boolean;
begin
If Str = '' then
begin
WordCnt := 0;
exit;
end;
SpaceBefore := true;
W := 0;
For I := 1 to length(Str) do
begin
If SpaceBefore and (Str[I] <> ' ') then
begin
W := succ(W);
SpaceBefore := false;
end
else
If (SpaceBefore = false) and (Str[I] = ' ') then
SpaceBefore := true;
end;
WordCnt := W;
end;
Function ExtractWords(StartWord,NoWords:byte;Str:string):string;
var Start, finish : integer;
begin
If Str = '' then
begin
ExtractWords := '';
exit;
end;
Start := LocWord(1,StartWord,Str);
If Start <> 0 then
finish := LocWord(Start,succ(NoWords),Str)
else
begin
ExtractWords := '';
exit;
end;
If finish = 0 then {5.02A}
finish := succ(length(Str));
Repeat
finish := pred(finish);
Until Str[finish] <> ' ';
ExtractWords := copy(Str,Start,succ(finish-Start));
end; {Func ExtractWords}
Function LocWord(StartAT,Wordno:byte;Str:string):byte;
{local proc used by PosWord and Extract word}
var
W,L: integer;
Spacebefore: boolean;
begin
If (Str = '') or (wordno < 1) or (StartAT > length(Str)) then
begin
LocWord := 0;
exit;
end;
SpaceBefore := true;
W := 0;
L := length(Str);
StartAT := pred(StartAT);
While (W < Wordno) and (StartAT <= length(Str)) do
begin
StartAT := succ(StartAT);
If SpaceBefore and (Str[StartAT] <> ' ') then
begin
W := succ(W);
SpaceBefore := false;
end else
begin
If (SpaceBefore = false) and (Str[StartAT] = ' ') then
SpaceBefore := true;
end;
end;
If W = Wordno then
LocWord := StartAT
else
LocWord := 0;
end;
function BFromStr;
begin
if Pos > 0 then
begin
Val(TrimRight(Copy(S, Pos, Len)), Value, Code);
Result := Code = 0;
end
else
Result := false;
if not Result then
Value := 0;
end;
function WFromStr;
begin
if Pos > 0 then
begin
Val(TrimRight(Copy(S, Pos, Len)), Value, Code);
Result := Code = 0;
end
else
Result := false;
if not Result then
Value := 0;
end;
function IFromStr;
begin
if Pos > 0 then
begin
Val(TrimRight(Copy(S, Pos, Len)), Value, Code);
Result := Code = 0;
end
else
Result := false;
if not Result then
Value := -99;
end;
function SFromStr;
begin
if Pos > 0 then
begin
Val(TrimRight(Copy(S, Pos, Len)), Value, Code);
Result := Code = 0;
end
else
Result := false;
if not Result then
Value := -99;
end;
function DFromStr;
begin
if Pos > 0 then
begin
Val(TrimRight(Copy(S, Pos, Len)), Value, Code);
Result := Code = 0;
end
else
Result := false;
if not Result then
Value := -99;
end;
end.