Solved

Finding parts of strings in http stream

Posted on 1997-10-15
4
163 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 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

7 Experts available now in Live!

Get 1:1 Help Now