String handling in Buffer

Hi Friends i'm writing a small utility in borland c++ builder which opens a telnet client reads the messages the Telnet Host sends. Based on the messages it sends i'm call my functions.I'm using the TIdTelnet Indy Client Component which comes built in with Borland C++ Builder 6.0.

The TIdTelnet component has an event handler called OnDataAvailable which handles all the messages sent by the host

The function is like this
//----------------------
void __fastcall TForm1::IdTelnet1DataAvailable(AnsiString Buffer)
{

}
//----------------------

Here Buffer is where all the messages are recieved

The Default Message i should get when i log on to the host is as below
-------------------
PCQLinux 2004 (NewDawn)
Kernel 2.4.22-1.2115.nptl on an i686
login:
-------------------
So my function should be something like this
//----------------------
void __fastcall TForm1::IdTelnet1DataAvailable(AnsiString Buffer)
{
AnsiString s;
s=Buffer;

if(s=="login: ")
{

IdTelnet1->WriteLn("postgres");
}
}
//----------------------
Here i'm waiting for the "login: " or in any case the last line to appear in buffer after which the function is called.

But the condition fails because when i check the value of "s" it will be some thing like this

"PCQLinux 2004 (NewDawn)\r\nKernel 2.4.22-1.2115.nptl on an i686\r\nlogin: "

So i did something like this but That to did not help

//----------------------
void __fastcall TForm1::IdTelnet1DataAvailable(AnsiString Buffer)
{
int Start, Stop;
Start = 1;
Stop = Buffer.Pos(IntToStr('\n')); //the character count to a CR in the buffer

if(Stop == 0)
Stop = Buffer.Length() + 1;

while(Start <= Buffer.Length())
{

s=Buffer.SubString(Start,Stop-Start);

if(Buffer.SubString(Stop,1)=='\n')
{

}
Start = Stop + 1;
if(Start > Buffer.Length())
{

break;
}
if(Buffer.SubString(Start,1)=='\n')
{
Start++;
}
Stop = Start;
while((Buffer.SubString(Stop, 1)!= '\n')&&(Stop <= Buffer.Length()))
{
Stop++;
}
}
value->Text=s;

if(s=="login: ")
{

IdTelnet1->WriteLn("postgres");

}
}
//----------------------
But still the problem repeats.Any help is greatly appreciated. Thanks in advance.
[2879 byte] By [perk40] at [2007-11-20 8:26:39]
# 1 Re: String handling in Buffer
It's very hard to read without code tags so may I instead suggest that all you search the buffer in reverse order for a '\n' and use that position+1 as starting point for the substring to test?
S_M_A at 2007-11-9 1:20:11 >
# 2 Re: String handling in Buffer
#include <iostream>
#include <cstring>

int main(){
using namespace std;
char buffer[] = "PCQLinux 2004 (NewDawn)\r\nKernel 2.4.22-1.2115.nptl on an i686\r\nlogin:";
char *ptc = strstr(buffer, "login:");
char *s = new char[strlen(ptc) + 1];
strcpy(s, ptc);
cout << s << endl;
return 0;
}
ne0n82 at 2007-11-9 1:21:11 >
# 3 Re: String handling in Buffer
Thanx guys i got it.
perk40 at 2007-11-9 1:22:12 >