Hi

I have strings that look like

"Answer: 1/3242"

"Answer: 132/643"

"Answer: 5/631543"

etc., and I need to compute the value of the fraction by e.g. extracting the top and bottom as substrings.

My first idea was to modify the two functions below, which search for the first and the last digit, to search for the first and the last series of digits. But this does not quite work. Are there simple ways to do this?

Thank you for your help!Code:int top_frac(const std::string& x) { std::string temp; int number = 0; for ( unsigned int i = 1; i < x.size(); i++ ) { if ( isdigit( x[i] ) ) { for ( unsigned int a = i; a < x.size(); a++ ) { temp += x[a]; } break; } } std::istringstream stream( temp ); stream >> number; return number; } int bot_frac(const std::string& x) { std::string temp; int number = 0; for ( unsigned int i = x.size(); i--; ) { if ( isdigit( x[i] ) ) { for ( unsigned int a = i; a < x.size(); a++ ) { temp += x[a]; } break; } } std::istringstream stream( temp ); stream >> number; return number; }

serge