Solved

Text Search

Posted on 2003-10-21
7
158 Views
Last Modified: 2010-04-05
Hi Experts!  Okay, I need to search a text file and retrieve info from it.  My info will be located between brackets: <info>.  Is there a procedure that can do this for me?  Any examples?
0
Comment
Question by:jennifere
[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
7 Comments
 

Expert Comment

by:adidi
ID: 9592355
hi there - here is my ideea , i don't know if it is the best but is an ideea

load the whole text file in a TRichEdit and then use the funtion "pos" , this function will give the position of the first mached string in the richedit
0
 

Author Comment

by:jennifere
ID: 9593303
That would work, but I don't know the string I'm looking for.  I want to search the text and find the address that will be enclosed in the <>.  I need find the first <, then read everything in between that and the last >.  
0
 
LVL 3

Accepted Solution

by:
philly_tee earned 20 total points
ID: 9596140
Hi,

You can load the file into a memo or richedit, (visible set to false if you dont want to see it), then use this to extract the text between the < >

Memo1.Text := Copy(Memo1.Text, Pos('<', Memo1.Text) + 1, Pos('>', Memo1.Text) - Pos('<', Memo1.Text) - 1);

all i am doing is copying from the '<' a number of characters defined by how far apart the '<' and '>' are. (If that makes sense?)

HTH

Philip
0
Technology Partners: 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!

 

Expert Comment

by:waldude
ID: 9597225
I don't have an example, but a sugestion would be to use regular expressions. A Regular expressions search would let you do what your wanting. Check out these sites:

http://www.latiumsoftware.com/en/articles/00009.php

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56reconIntroductionToRegularExpressions.asp

Or just Google for Regular Expressions, you'll find lots.
Good luck.

Brandon
0
 

Expert Comment

by:bullsrl
ID: 9598909
I don't claim to be an expert but this is what I came up with, it loads from a text file and output's your <Info> to another text file hope it works

James

procedure FindInfo();
   var
   InFile, OutFile: TextFile;
   Line, InfoString: string;
   Lpointer, LEnd: PChar;
   Info, EndOfInfo: Boolean;
   LeftBracket, RightBracket: Char;
begin
   Info := False;
   EndOfInfo := False;
   LeftBracket := '<';
   RightBracket := '>';

   AssignFile(InFile, 'C:\test.txt');
   AssignFile(OutFile, 'C:\finsihed.txt');
   try
   begin
      Reset(InFile);
      Rewrite(OutFile);
      while not Eof(InFile) do
      begin
         //Read the line
         Readln(InFile, Line);
         LPointer := Strscan(PChar(Line), LeftBracket);
         if LPointer <> nil then
         begin
            Info := True;
         end;
         if Info then
         begin
            LPointer := LPointer + 1;
            LEnd := StrScan(LPointer, RightBracket);
            if LEnd <> nil then
            begin
               LEnd := StrLCopy(LEnd, LPointer, Strlen(PChar(LPointer)) - StrLen(LEnd));
               Info := False;
            end
            else
            begin
               InfoString := LPointer;
               while not EndOfInfo do
               begin
                  Readln(InFile, Line);
                  lEnd := StrScan(PChar(Line), RightBracket);
                  if LEnd <> nil then
                  begin
                     LEnd := StrLCopy(LEnd, PChar(Line), Strlen(PChar(Line)) - StrLen(LEnd));
                     EndOfInfo := True;
                     InfoString := InfoString + ' ' + LEnd;
                  end
                  else
                     InfoString :=  InfoString + ' ' + Line;
               end;
            end;
            Writeln(OutFile, InfoString);
         end;
      end;
   end;
   CloseFile(InFile);
   CloseFile(OutFile);
   except
   end;
end;
0
 

Author Comment

by:jennifere
ID: 9600008
Thanks for all your comments!  I going to give the points to philly_tee, because his solution worked within the first five minutes.
0
 
LVL 3

Expert Comment

by:philly_tee
ID: 9602651
Thanks for the points,

Glad I could help :)

Philip
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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