I want to extract integers from a certain string in order to perform mathematical operations on them.
For example for a string
25 1 3; 5 9 2; 1 3 6
I only want to extract
25, 1, 3, 5, 9, 2, 1, 3, 6
is there a way I can do that?
I would just use the String Toolkit to parse the strings using spaces, brackets and semicolon as the delimiters.
I have answered the questions before Extract Data from a line
I paraphrased that code below:
#include <strtk.hpp> // http://www.partow.net/programming/strtk
std::string src = "[25 1 3; 5 9 2; 1 3 6]";
std::string delims(" [];");
std::vector<int> values;
strtk::parse(src, delims, values );
// values will contain all the integers in the string.
// if you want to get floats & integers the vector needs to be float
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With