Solved

Finding parts of strings in http stream

Posted on 1997-10-15
4
160 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
For a quick and relevant answer I give everything I've got...
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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

14 Experts available now in Live!

Get 1:1 Help Now