Re: Help splitting a simple date string
* yogi_bear_79:
I have a simple string (i.e. February 27, 2008) that I need to split
into three parts. The month, day, and year. Splitting into a string
array would work, and I could convert day and years to integers
later. I've bene looking around, and everything I see seems more
complicated than it should be! Help!
Many ways. One has already been illustrated by Daniel T else-thread,
using built-in std::string functions. The simplest would possibly be to
use a regular expression, but then you need to know about those.
Somewhere in the middle (disclaimer: code not touched by compiler's hands):
std::vector<std::string> splitOnWhitespace( std::string const& s )
{
std::istringstream stream( s );
std::string component;
std::vector<std::string> result;
while( s >> component ) { result.push_back( component ); }
return result;
}
Here I just let delimiters such as that comma hang on. They'll be
removed by conversion to numeric later.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?