Solved

Text Search

Posted on 2003-10-21
7
152 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 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now