Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Finding parts of strings in http stream

Posted on 1997-10-15
4
Medium Priority
?
167 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

610 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