Solved

Text Search

Posted on 2003-10-21
7
159 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month6 days, 9 hours left to enroll

634 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