#include <regex>
#include <boost/lexical_cast.hpp>
std::cmatch matches;
std::regex regExp("\\s{0,}([0-9]+)\\s{0,}x([0-9]+)\\s{0,}x\\s{0,}([0-9]+)\\s{0,}", std::regex_constants::icase);
if (std::regex_match("100X200 x 300", matches, regExp)) {
unsigned int width = boost::lexical_cast<unsigned int>(matches[1].str());
unsigned int height = boost::lexical_cast<unsigned int>(matches[2].str());
unsigned int depth = boost::lexical_cast<unsigned int>(matches[3].str());
}
Show differencesHistory of post edits
#Actualsimast
Posted 29 December 2012 - 01:58 AM
Another approach (with regular expressions and boost lexical cast):
#2simast
Posted 29 December 2012 - 01:58 AM
Another approach (with regular expressions and boost lexical cast):
#include <regex>#include <boost/lexical_cast.hpp>std::cmatch matches;std::regex regExp("\\s{0,}([0-9]+)\\s{0,}x([0-9]+)\\s{0,}x\\s{0,}([0-9]+)\\s{0,}", std::regex_constants::icase);if (std::regex_match("100X200 x 300", matches, regExp)) { unsigned int width = boost::lexical_cast<unsigned int>(matches[1].str()); unsigned int height = boost::lexical_cast<unsigned int>(matches[2].str()); unsigned int depth = boost::lexical_cast<unsigned int>(matches[3].str());}
#1simast
Posted 29 December 2012 - 01:54 AM
Another approach (with regular expressions and lexical cast):
#include <regex>
#include <boost/lexical_cast.hpp>
std::cmatch matches;
std::regex regExp("\\s{0,}([0-9]+)\\s{0,}x([0-9]+)\\s{0,}x\\s{0,}([0-9]+)\\s{0,}", std::regex_constants::icase);
if (std::regex_match("100X200 x 300", matches, regExp)) {
unsigned int width = boost::lexical_cast<unsigned int>(matches[1].str());
unsigned int height = boost::lexical_cast<unsigned int>(matches[2].str());
unsigned int depth = boost::lexical_cast<unsigned int>(matches[3].str());
}