Solved

Strip Certian lines of text from Memo

Posted on 2004-10-03
10
320 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 30

Author Comment

by:Wayne Barron
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 30

Author Comment

by:Wayne Barron
Comment Utility
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
Comment Utility
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
Comment Utility
Hi,
Come on guys. Don't be so strict. Let it be as it is.
Cheers :)
0
 
LVL 30

Author Comment

by:Wayne Barron
Comment Utility
:-) 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
Comment Utility
[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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

10 Experts available now in Live!

Get 1:1 Help Now