We help IT Professionals succeed at work.

High Speed Text Extraction

rife2676 asked
Medium Priority
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?
Watch Question

Here is a simple snippet, a bit "C'esh" as you may see.

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

procedure Process;
  Line: array[0..255] of Char;
  PBol, PEol: PChar;
  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
    if (PBol-1)^ <> '#' then begin // and here is the check
      ShowMessage('Fatal: encountered: ' + Line);
    PEol := PBol;
    while PEol^ <> ' ' do Inc(PEol);
    PEol^ := #0;
    WriteLn(PBol); // or do whatever you need with PBol

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
Could you please tell what was wrong?



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.
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
  CharIndex := Pos('#', Line) + 1;
  while Line[CharIndex] <> ' ' do
    RoomName := RoomName + Line[CharIndex];

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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];

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.