Sign in to follow this  
rholding2001

delimiting a text string

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this