cando
asked on
STRINGS
i have a memo that looks something like this...
DTITLE=any string
DTITLE=any string
TTITLE0=any string
TTITLE1=any string
TTITLE2=any string
TITTLE3=any string
TTITLE3=any string
i need to fill in another memo with each string in the line that the number before it says. I then need to delete the beginning of the line, the part that says TTitle1=. and if there are two lines in the string with the same number (like TTITLE3=) then they are both added to the same line(for TTITLE3=anystring, the memo line 3 would look like this anystringanystring).
I need to do this automatically for each line in the memo.
how can this be done?
cando
DTITLE=any string
DTITLE=any string
TTITLE0=any string
TTITLE1=any string
TTITLE2=any string
TITTLE3=any string
TTITLE3=any string
i need to fill in another memo with each string in the line that the number before it says. I then need to delete the beginning of the line, the part that says TTitle1=. and if there are two lines in the string with the same number (like TTITLE3=) then they are both added to the same line(for TTITLE3=anystring, the memo line 3 would look like this anystringanystring).
I need to do this automatically for each line in the memo.
how can this be done?
cando
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi cando, hi rwilson
i have a little change done in rwilsons answer (excuse me rwilson), because i think that any String can hold diferent strings like
DTITLE=any string 1
DTITLE=any string 2
TTITLE0=any string 3
TTITLE1=any string 4
TTITLE2=any string 5
TITTLE3=any string 6
TITTLE3=any string 7
and Raymond compares the whole line, so that are no duplicates be detected before the =-Sign if the string after = is a other
procedure PopulateMemo(Source, Dest : TMemo);
var
s : TStringList;
Index : Integer;
Str : String;
begin
s := TStringList.Create;
s.Assign(Source.lines);
Dest.clear;
while s.count > 0 do
begin
str := s.Names[0];
Dest.lines.add(s.Values[St r]);
s.delete(0);
index := 0;
while index < s.count do
begin
if str = s.Names[Index] then
begin
Dest.Lines[Dest.Lines.coun t - 1] :=
Dest.Lines[Dest.Lines.coun t - 1] + s.Values[Str];
s.delete(Index);
dec(Index);
end;
Inc(Index);
end;
end;
s.Free;
end;
This results in
any string 1any string 2
any string 3
any string 4
any string 5
any string 6any string 7
meikl
i have a little change done in rwilsons answer (excuse me rwilson), because i think that any String can hold diferent strings like
DTITLE=any string 1
DTITLE=any string 2
TTITLE0=any string 3
TTITLE1=any string 4
TTITLE2=any string 5
TITTLE3=any string 6
TITTLE3=any string 7
and Raymond compares the whole line, so that are no duplicates be detected before the =-Sign if the string after = is a other
procedure PopulateMemo(Source, Dest : TMemo);
var
s : TStringList;
Index : Integer;
Str : String;
begin
s := TStringList.Create;
s.Assign(Source.lines);
Dest.clear;
while s.count > 0 do
begin
str := s.Names[0];
Dest.lines.add(s.Values[St
s.delete(0);
index := 0;
while index < s.count do
begin
if str = s.Names[Index] then
begin
Dest.Lines[Dest.Lines.coun
Dest.Lines[Dest.Lines.coun
s.delete(Index);
dec(Index);
end;
Inc(Index);
end;
end;
s.Free;
end;
This results in
any string 1any string 2
any string 3
any string 4
any string 5
any string 6any string 7
meikl
Kretzschmar: Thanks for the fix with the count-1 bit (I still wonder why they made these things 0 based). I had forgotten about the names and values properties of TStringList!
Cheers,
Raymond.
Cheers,
Raymond.
ASKER
thanks for that fix Kretzschmar.
this part of the answer
if Index > -1 then
begin
s.delete(Index);
Dest.Lines[Dest.Lines.coun
Dest.Lines[Dest.Lines.coun
end;
should be
if Index > -1 then
begin
s.delete(Index);
Dest.Lines[Dest.Lines.coun
Dest.Lines[Dest.Lines.coun
end;
meikl