Solved

High Speed Text Extraction

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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