Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting up Incoming Info.....

Status
Not open for further replies.

LoneRanger123

Programmer
Dec 19, 2000
62
GB
Im making a program to Query Halflife Servers, using UDP, and when I send "info", it returns:

"info"
Server responds with the following packet:
(int32) -1
(byte) ASCII 'C' (info response, S2A_INFO)
(string) net address of server
(string) name of the host / server
(string) name of the map
(string) game directory (i.e. valve/)
(string) Game description (e.g. "half-life multiplay")
(byte) active client count
(byte) maximum clients allowed
(byte) protocol version (currently 7)

....

How can I split all that up into Strings?
Do AnsiStrings automatically truncate to the first NULL char?


here is my current code (dont work);
Code:
                  AnsiString C;
      TMemoryStream *MyStream = new TMemoryStream();
  NMUDP1->ReadStream(MyStream);
  C.SetLength(NumberBytes);
  MyStream->Read(&C[1], NumberBytes);

    int tempI= 1;

  while (tempI <= NumberBytes) {
  int Temp;
  Temp = atoi(&C[tempI]);
        if (Temp == 3) {

        &C[tempI] == &quot;-&quot;;
        }
                               //MessageDlg(&C[tempI],mtError,TMsgDlgButtons() << mbOK,0);
        tempI++;
  }

               MessageDlg(C,mtError,TMsgDlgButtons() << mbOK,0);

That returns everything up to the end of the net address of server (end of first String). That code trys to replace it, that was me testing. I would preferably like it in different strings, an array.

TY for any help :) You dont have to supply code if u dont want, just give me some pointers and ill try to figure it out.
 
One of the nice things about AnsiString is that it has some neat operators. Look closely at the SubString(int index, int count) and Pos(const AnsiString& subStr)classes.
Code:
int Position = C.Pos(&quot;-&quot;);
AnsiString FirstPart = C.SubString(1,Position-1);
AnsiString SecondPart = C.SubString(Postion+1, NumberBytes);

I'm doing this from memory so you may have to play with the code a bit. Also, it is a good idea to put some error checking in, e.g., what happens when &quot;-&quot; isn't found. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top