Solved

Strip Certian lines of text from Memo

Posted on 2004-10-03
10
324 Views
Last Modified: 2010-04-05
Hello All;

  I need to strip certain lines of text from a TMemo.
This is what I need to do.

I need to look through the TMemo, and find all lines that have the    /
On them. If they do, I need to delete the entire line.
Then loop through the TMemo and delete all "ending" text after the " : Colon
"

Example:
=========================
Huun Huur Tu : Huun_Huur_Tu/
Hvorostovsky, Dmitri :
/Top/Arts/Music/Vocal/Singers/Classical/H/Hvorostovsky,_Dmitri/
Hynde, Chrissie : /Top/Arts/Music/Bands_and_Artists/P/Pretenders/
Hynes, Nina : Hynes,_Nina/
=========================

OK. The text above. "1st & 4th lines" I need to keep.
"2nd & 3rd" Lines I need to delete.

Then I need to delete everything from the    :Colon  to the "Right" of it.
( That means that I need the "Colon : " deleted along with its
Text to the Right of it )
As you can see in the Text above. Every line has a   : Colon
Between the words

Using:
Memo1.Text := StringReplace(Memo1.Text, '/Top/', '', [rfReplaceAll,
rfIgnoreCase]);

The above will only delete the [  /Top/ ] from each line in the TMemo.

Any information on how I can accomplish this would be extremely helpful.

Carrzkiss
0
Comment
Question by:Wayne Barron
  • 4
  • 3
  • 3
10 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 12213312
Hi,
If I understand You well this should work

procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  p: integer;
begin
  for i := Memo1.Lines.Count-1 downto 0 do
    if Pos('/',Memo1.Lines[i]) > 0 then
      Memo1.Lines.Delete(i);
  for i := Memo1.Lines.Count-1 downto 0 do
    begin
    p := Pos(':',Memo1.Lines[i]);
    if p > 0 then
      Memo1.Lines[i] := Copy(Memo1.Lines[i],1,p-1);
    end;
end;
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 55 total points
ID: 12213410
unit Unit1_Q_21154212;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private   { Private declarations }
  public    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Remove: Boolean;
  I:      Integer;
  IColon: Integer;
  SL:     TStringList;
  S:      string;
begin
  Memo2.Clear;
  SL := TStringList.Create;
  try
    for I := 0 to Memo1.Lines.Count-1 do
    begin
      S := Memo1.Lines[I];
      IColon := Pos(':', S);
      if (IColon=0) then
        Remove := True
      else
        Remove := (Pos('/Top/', S)>0);
      if not Remove then
      begin
        Delete(S, IColon, Length(S)-IColon+1);
        SL.Add(S);
      end;
    end;
  finally
    Memo2.Lines.Assign(SL);
    SL.Free;
  end;
end;

end.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 12213989
Hello [mokule]

  You code will get rid of everything. :-(
I do not need to get rid of everything. Please re-read the
Information on what I am needing again, please?

Carrzkiss
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 30

Author Comment

by:Wayne Barron
ID: 12214005
Thank You [esoftbg];

Once again, you have come through for me :-)

Now time to look at your code, and see how it all works.

Thank you once again.

0
 
LVL 17

Expert Comment

by:mokule
ID: 12215065
Hi,
>> I need to look through the TMemo, and find all lines that have the    /
On them.

Not everything I think. My code fulfills Your specification.

If You replace '/' with '/Top/' in my code it will fulfills Your requirements ;)
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 12215161
Hello [mokule]:

  Yes you code does. And for this I do appologise.
I just did a quick test on it, and did not think about
changing the marks in the code, to suit what I was
Needing.

This should have been a [ Point Split ] between you and esoftbg

If you want, I can post another question and direct it to you, ( When I think of something ) and I will post it in here, as long as you are watching this question still ?

Let me know

Once again, I am sorry.
Your code works great.

Carrzkiss
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12215252
Hello [carrzkiss] and [mokule],

I could solve the problem about this question by providing personally to [mokule] a new question for 55 points and when he post a comment, to accept it with grade A.

Are you agree ?
0
 
LVL 17

Expert Comment

by:mokule
ID: 12215342
Hi,
Come on guys. Don't be so strict. Let it be as it is.
Cheers :)
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 12216868
:-) But we like to be strict :-)
It is in the Delphi programmers nature :-)

ESoftBG, it is ok.
Mokule, I will keep you in mind for a later question.

Take Care all
carrzkiss
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12216991
[mokule],

I posted for you a question:
http://experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21154563.html

Please post a comment there ....
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now