delimiting a text string
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
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement