Subj : Final code
To : Sean Dennis
From : mark lewis
Date : Fri May 07 2010 10:17 am
SD> I couldn't resist relaxing a bit and working on some code, so I got
SD> the code finalized and it compiles. Now to see if it actually
SD> works. :)
here's another post that only pulls out the space delimited fields and this one
is zero-based... field 0 is 'A', 1 is 'Daryl', 3 is the comma delimited section
and so on...
another item of interest about this routine... it looks like, by default, it
extracts words that are space, tab or semi-colon (;) delimited... but anyway,
there it is :)
var
my_cnt : integer;
my_str,
result_str : string;
function extractword(str : string; n : integer) : string;
var
count : integer;
i : integer;
len : integer;
done : boolean;
retstr : string;
begin
retstr := '';
len := length(str);
count := -1;
i := 1;
done := false;
while (i <= len) and (not done) do
begin
while ((i <= len) and
((str[i] = #32) or
(str[i] = #9) or
(str[i] = ';'))) do
inc(i);
if i <= len then
inc(count);
if count = n then
begin
retstr[0] := #0;
if (i > 1) then
if str[i-1] = ';' then
retstr := ';';
while ((i <= len) and
((str[i] <> #32) and
(str[i] <> #9) and
(str[i] <> ';'))) do
begin
inc(retstr[0]);
retstr[ord(retstr[0])] := str[i];
inc(i);
end;
done := true;
end
else
while ((i <= len) and
((str[i] <> #32) and
(str[i] <> #9) and
(str[i] <> ';'))) do
inc(i);
end;
extractword := retstr;
end;
begin
my_str := t1_str + t2_str + t3_str + t4_str;
writeln(my_str);
for my_cnt := 0 to 9 do
begin
result_str := extractword(my_str,my_cnt);
writeln(my_cnt, ' : ''',result_str,'''');
end;
end.