Need help with strings

Im making a chat program and i want to have commands that start with '/'.

So for the command /nick name, i need help breaking the string up.

I need something like,
1
2
if( beginningOfBuffer == /nick )
    change ID to endHalfOfBuffer(which would contain 'name')


I never really had to use strings in any complicated way so i have no idea how to do this.
Aha so c_str splits things into tokens... I think thats useful information. Im still looking for help though heh
First of all you can define string literal "nick " as a const pointer. For example

const char *nickname = "nick ";

and then use the following if statement

1
2
3
4
if ( buffer[0] == '/' && substr( buffer, 1, std::strlen( nickname ) ) == nickname )
{
   // change ID to endHalfOfBuffer(which would contain 'name')
}  
Last edited on
Topic archived. No new replies allowed.