?
Solved

STRINGS

Posted on 1999-01-11
5
Medium Priority
?
184 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:cando
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 400 total points
ID: 1355887
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.strings[0];
      Dest.lines.add(copy(str, pos('=', str) + 1, length(str)));
      s.delete(0);
      repeat
        Index := S.IndexOf(Str);
        if Index > -1 then
          begin
            s.delete(Index);
            Dest.Lines[Dest.Lines.count] :=
            Dest.Lines[Dest.Lines.count] + copy(str, pos('=', str) + 1, length(str));
          end;
      until Index = -1;
    end;
  s.Free;
end;

end.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1355888
Hi Cando, Hi Rwilson,

this part of the answer

if Index > -1 then
begin
  s.delete(Index);
  Dest.Lines[Dest.Lines.count] :=
  Dest.Lines[Dest.Lines.count] + copy(str, pos('=', str) + 1, length(str));
end;

should be

if Index > -1 then
begin
  s.delete(Index);
  Dest.Lines[Dest.Lines.count - 1] :=
  Dest.Lines[Dest.Lines.count - 1] + copy(str, pos('=', str) + 1, length(str));
end;


meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1355889
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[Str]);
    s.delete(0);
    index := 0;
    while index < s.count do
    begin
      if str = s.Names[Index] then
      begin
        Dest.Lines[Dest.Lines.count - 1] :=
        Dest.Lines[Dest.Lines.count - 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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1355890
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.

0
 

Author Comment

by:cando
ID: 1355891
thanks for that fix Kretzschmar.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question