Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Searching through a Textfile

Posted on 2003-03-19
6
Medium Priority
?
183 Views
Last Modified: 2010-04-04
I have a textfile.
Each block of the Textfile begins with a title which is enclosed in square brackets.
i.e.
[TITLE]
Data within Block.

At the moment my textfile is being read into and displayed in a RichEdit box.
What I want to do is search through my textfile for each Title and then display all titles in a memo(without the square brackets).
Is there a simple pre-defined search routine which will do this? Or where do I start if I have to write my own search routine?

Thanks in advance guys!
0
Comment
Question by:Degsy
  • 2
4 Comments
 

Accepted Solution

by:
da-vinci earned 100 total points
ID: 8169772
Yes there is a simple search routine.
I always use the search routines from madshi. (http://www.madshi.net/)

There are a lot of possibilities with these string routines. It took me 3 minutes to make your request:



unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    RichEdit1: TRichEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    i,
    til: Integer;
    title: String;
begin
    Memo1.Clear;
    for i:= 0 to RichEdit1.Lines.Count-1 do
    begin
        if TextMatch(RichEdit1.Lines[i], '[*]') then     // TRUE if title exists
        begin
            til:=  PosStr(']', RichEdit1.Lines[i]);      // Position of ']'
            title:= MidStr(RichEdit1.Lines[i], 2, til-2);// capture title
            Memo1.Lines.Add(title);
        end;
    end
end;

end.

0
 
LVL 1

Expert Comment

by:jturpin
ID: 8169779

Try reading it into a TStringList usinf the LoadFromFile method.

Then locate the '[' using IndexOf etc. Then copy the title out and put it in your RichEdit.

Of course if each line begins with '[' simply find ']' and copy the text into your RichEdit.

for i:= 0 to StringList1.Count-1 do
begin
  dx:= Pos(']', StringList1.Strings[i];
  if (dx > 0) then
    RichEdit1.Lines.Add(Copy(StringList1.Strings[i],2,dx))
  else
    RichEdit1.Lines.Add('>> Untitled: Copy(StringList1.Strings[i],2,10));
end; {for i}

John.
0
 

Expert Comment

by:da-vinci
ID: 8169801
So forgot to tell:
1) download and install madshi package
2) put "madStrings" in your uses

That should be enough to have:
PosStr
TextMatch
StrMatch
UpChar
etc.
0
 

Expert Comment

by:CleanupPing
ID: 9316677
Degsy:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

564 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