Subj : A little stringing along
To : Sean Dennis
From : mark lewis
Date : Thu May 06 2010 12:54 pm
SD> What I'm wanting to do is this: I want to start at the beginning of
SD> the line and read each "block" that's delimited by spaces into a
SD> string, so I can put the last name in one string, the first name in
SD> one string, the graphics type in another string, the DCE rate in
SD> another, so on and so forth. All data will be treated as strings
SD> and this will be read from a text file, so it's pretty easy to get
SD> the data in.
here's something i had laying around... the original used a ';' as a divider
with #32 and #9... i just changed the ';' to ',' so it would break out all of
the comma delimited fields as well... it is the 3rd "str[i]" in each of the
three while lines...
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 := 0;
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 28 do
begin
result_str := extractword(my_str,my_cnt);
writeln(my_cnt, ' : ''',result_str,'''');
end;
end.