?
Solved

Finding parts of strings in http stream

Posted on 1997-10-15
4
Medium Priority
?
166 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
[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
  • 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 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