Solved

Strip Certian lines of text from Memo

Posted on 2004-10-03
10
327 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 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Strange behavior when a form is closed 6 79
Convert a string into a TDateTime 5 80
SUM 2 INTEGER ARRAYS INTO 1 10 117
Slow Restore if incremental backups using RDiff.exe 4 51
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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