Solved

High Speed Text Extraction

Posted on 1997-11-22
5
138 Views
Last Modified: 2010-04-04
I have made a simple IRC client in Delphi 2.x and I am having problems getting the IRC rooms.  When I call the server to list the rooms, it returns data like this:

<----begin data---->
:golden.on.ca.dal.net 322 rryan #sable 1 :
:golden.on.ca.dal.net 322 rryan #TazMan 1 :
:golden.on.ca.dal.net 322 rryan #Vampyras 1 :
:golden.on.ca.dal.net 322 rryan #fuel 1 :fueled by
:golden.on.ca.dal.net 322 rryan #gaspesie 1 :
<----End Data---->

How do I have my delphi get the room names (between # and space)??  The server sends the data at a rate of 100's of lines per sec, how can I have it get the rooms in real-time?
0
Comment
Question by:rife2676
  • 3
5 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1351470
Here is a simple snippet, a bit "C'esh" as you may see.

--//--
const
  ServerName: string = 'golden.on.ca.dal.net';
  UserName: string = 'rryan';

procedure Process;
var
  Line: array[0..255] of Char;
  PBol, PEol: PChar;
begin
  Line := #0;
  PBol := Line + Length(ServerName) + Length(UserName) + 8;  // pointer to the char next of '#'
  while not(Eof) and (StrComp(Line, '<----End Data---->') <> 0) do begin
    (PBol-1)^ := #0;  // so that we may check if we got a valid string
    ReadLn(Line);
    if (PBol-1)^ <> '#' then begin // and here is the check
      ShowMessage('Fatal: encountered: ' + Line);
      Exit;
    end;
    PEol := PBol;
    while PEol^ <> ' ' do Inc(PEol);
    PEol^ := #0;
    WriteLn(PBol); // or do whatever you need with PBol
  end;
end;
--//--

Maybe you don't even need the check.
I think there are no faster ways than using PChar types to process the strings.

HTH, julio
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1351471
Could you please tell what was wrong?

Thanks
0
 

Author Comment

by:rife2676
ID: 1351472
It's C++/C code, and it does me no good...there is no strcmp in pascal that i know of....I need a simple delphi app that returns only the rooms nothing more....make it simpler and convert all to delphi/OOP and you got the points.
0
 
LVL 1

Accepted Solution

by:
TheSwine earned 50 total points
ID: 1351473
The term Real time is not the exact case here. and what if it will take 3 secs to find all those rooms from the orginal strings?
in what way do you recive this data? string? buffers? or what?

If you get strings, do something like that:
For each line do
begin
  CharIndex := Pos('#', Line) + 1;
  while Line[CharIndex] <> ' ' do
  begin
    RoomName := RoomName + Line[CharIndex];
    Inc(CharIndex);
  end;
end;

if what you get is a buffer, scan it for '#' when found just read it until the ' '.
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1351474
Well, that _is_ Delphi/OOP (i've even tested it!).
And, StrComp (not strcmp) is a null-terminated-string handling routine you may find in SysUtils.

That is the faster approach you may find; compare the two extracting cores:

--//--
  PEol := PBol;
  while PEol^ <> ' ' do Inc(PEol);
  PEol^ := #0;
  // now RoomName is in PBol;
--//--

--//--
CharIndex := Pos('#', Line) + 1;
while Line[CharIndex] <> ' ' do begin
  RoomName := RoomName + Line[CharIndex];
  Inc(CharIndex);
end;
--//--

-julio
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
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.

759 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

24 Experts available now in Live!

Get 1:1 Help Now