Need help with strings

Nov 18, 2012 at 11:08pm
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.
Nov 18, 2012 at 11:36pm
Aha so c_str splits things into tokens... I think thats useful information. Im still looking for help though heh
Nov 19, 2012 at 12:04am
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 Nov 19, 2012 at 12:05am
Topic archived. No new replies allowed.