delimiting a text string

Started by
0 comments, last by paradoxnj 19 years, 5 months ago
ok my client at the moment sends and recieves messages. what i would like to do is apply a protocol that sends a ~ before a command and the start of a message. for eg to send a message in the client would look like this MSG~hello there - the msg means that im sending a msg to say the chat room. how do i go about doing this. thanks
visit my site http://www.fullf1.com for all your formula 1 and music creation needs.
Advertisement
If you are using std::string, look up string::find_first_of(). It's a really useful function for string parsing.

If you are not, then a string is just an array of characters. To parse out the command just loop until you find the '~'. To get the data, continue the loop from where you left off with the command + 1. Loop until you reach the end of the string (e.g \0, \n, \r).
Anthony Rufrano
RealityFactory 2 Programmer

This topic is closed to new replies.

Advertisement