Solved

High Speed Text Extraction

Posted on 1997-11-22
5
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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