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

x
?
Solved

Text Search

Posted on 2003-10-21
7
Medium Priority
?
161 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
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 80 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
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. …

824 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