Solved

Finding parts of strings in http stream

Posted on 1997-10-15
4
161 Views
Last Modified: 2010-04-04
I would like to find a way to extract strings from a stream returned from a http component. The strings i am looking for consists of unknown decimal numbers and there exact location is also unknown. The only thing that is known is a short string tag a unknown number av charcters before the wanted stringsegment.
0
Comment
Question by:tomasupp
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1347610
Tommasupp,

Could you post an example of what this string looks like? In general, the more "unknowns" when parsing a string, the more logic has to be built in to make it understandable to the application.

Also, the type of component your using might be relevant here. I have some code that parses strings from an NNTP component if that might be of value to you.

regards,
Pegasus
0
 

Author Comment

by:tomasupp
ID: 1347611
To be more specific I want to find numerical data from html documents to put in my own database. A typical line (not necessairily in the begining of the stream) would be:


306 | <!-- plugg -->AGA A                |  -0.50 |  123.00 | 123.50 | 123.00 | 123.50 | 122.00 |  183025 |  22515630 |  0.38

where the text 'AGA A' is the known 'code' and the wanted numerical value is 123.00 (the first one). The problem is not with the http component. I am able to 'see' the text stream and put it in a memo-component or a textfile etc. I just need som intelligent way to extract the data I want.

Tomas
0
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 100 total points
ID: 1347612
procedure TForm1.Button1Click(Sender: TObject);
var iAGA_OffSet,      {Keeps track of where "AGA A" is in the line}
    iSkippy: Integer; {used in loop}
begin
{We assume the text to be parsed is in Memo1}
{further assume that we want to store the parsed values in ListBox1}
With Memo1 DO
  Begin
  While Memo1.Text <> '' DO
     Begin
     iAGA_Offset := Pos('AGA A', Memo1.Text);
      if iAGA_Offset >0 then
       begin
       {Let's throw away anything before the "AGA A" since we don't need it.}
       Memo1.Text := Copy(Memo1.Text, iAGA_Offset,Length(Memo1.Text));
       {since "AGA A" is now at the beginning of the line, set the offset to 1}
       iAGA_Offset := 1;
       {String should now look like "AGA A | -0.50 | 123.00 | 123.50 | 123.00...
        and we need to skip the first two vertical bars to find our value}
       For iSkippy := 1 to 2 Do
           Memo1.Text := Copy(Memo1.Text, Pos('|',Memo1.Text)+1,Length(Memo1.Text));
       {our needed value is now at the beginning of the line, let's add it to
        a list box that contains the parsed values}
       ListBox1.Items.Add(Copy(Memo1.Text,0,Pos('|',Memo1.Text)-1));
       end
      else
       Memo1.Text := ''; {AGA A not found to clear memo for next parse}
     end;
  end;
end;

0
 

Author Comment

by:tomasupp
ID: 1347613
For a quick and relevant answer I give everything I've got...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 139
Best Firemonkey component pack 1 85
Dev Express grid collapse 2 39
FMX and jaudiotracker playing memory stream 29 66
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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

17 Experts available now in Live!

Get 1:1 Help Now