police45s
asked on
searching a string, stripping out substrings.
I have a string, for ex
welcome.to.my.nightmare.al ice.cooper
I want to put this string into 6 different variables so break on all .'s
with the following I'm only available to break on the first portion of the string (welcome)
for (i=0;i<counter;i++){
cout << strings[i] << endl;
j= strings[i].find(period);
output = strings[i].substr(0,j);
cout << output << endl;
how do I break on the other periods, there will be 30 other strings so each index of the period will change.
welcome.to.my.nightmare.al
I want to put this string into 6 different variables so break on all .'s
with the following I'm only available to break on the first portion of the string (welcome)
for (i=0;i<counter;i++){
cout << strings[i] << endl;
j= strings[i].find(period);
output = strings[i].substr(0,j);
cout << output << endl;
how do I break on the other periods, there will be 30 other strings so each index of the period will change.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hmm, they're basically the exact same thing.
>>> Hmm, they're basically the exact same thing
No, there are differences: your's compiles, mine has a wrong type string::size_t, should be string::size_type ;-)
Regards, Alex
No, there are differences: your's compiles, mine has a wrong type string::size_t, should be string::size_type ;-)
Regards, Alex
for (i=0;i<counter;i++)
{
cout << strings[i] << endl;
string::size_t pos = 0;
string::size_t lpos = 0;
while ((pos = strings[i].find(period, lpos)) != string::npos)
{
output = strings[i].substr(lpos,pos
cout << output << endl;
lpos = pos + 1;
}
// print the last substring as well
output = strings[i].substr(lpos);
cout << output << endl;
}
Regards, Alex