Solved

High Speed Text Extraction

Posted on 1997-11-22
5
139 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

12 Experts available now in Live!

Get 1:1 Help Now