Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Strip Certian lines of text from Memo

Posted on 2004-10-03
10
Medium Priority
?
329 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
[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
  • 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 220 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 31

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

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 31

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 31

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

730 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