Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Strip Certian lines of text from Memo

Posted on 2004-10-03
10
Medium Priority
?
330 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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