-
Chopping up strings
Hey everyone this is just a quick question.
I have a string that looks like this
Code:
string Name = "Hello everyone\n\nMy name is stovellp";
I want to break it up so I have "Hello everyone" in one string, and "My name is stovellp" in the other.
If anyone could point me on the trail for what functions I should look for I would really appreciate it.
-
boost::string_tokenizer from www.boost.org
-
Thanks for the reply CornedBee, I've looked at boost in the past but I'm not too trusting with downloading and configuring external libraries (Because I hate to read documentation mostly).
Before your reply I ended up writing a function of my own to do it just using a counter.
-
This should work,
Code:
#include <iostream>
#include <string>
#include <stdlib.h>
int main()
{
string Name = "Hello everyone\n\nMy name is stovellp";
string newName, newName2;
int loc = Name.find("\n\n",0);
if (loc != string::npos)
{
newName = Name.substr(0, loc);
newName2 = Name.substr( (loc + 2), Name.length() );
}
else
cout << "Couldnt find \\n\\n" << endl;
cout << newName << endl;
cout << newName2 << endl;
system("PAUSE");
return 0;
}