useful functions: split string to double added

pull/1/head
Thorsten Liebig 2012-09-17 11:51:19 +02:00
parent f29ac7aa84
commit 0de3d0caf0
2 changed files with 17 additions and 0 deletions

View File

@ -89,3 +89,19 @@ std::vector<float> SplitString2Float(std::string str, std::string delimiter)
} }
return v_f; return v_f;
} }
std::vector<double> SplitString2Double(std::string str, std::string delimiter)
{
std::vector<double> v_f;
std::vector<std::string> results;
boost::split(results, str, boost::is_any_of(delimiter));
for (size_t n=0;n<results.size();++n)
{
std::istringstream is(results.at(n));
double num;
if (is >> num)
v_f.push_back(num);
}
return v_f;
}

View File

@ -31,5 +31,6 @@ double CalcNyquistFrequency(unsigned int nyquist, double dT);
std::vector<unsigned int> AssignJobs2Threads(unsigned int jobs, unsigned int nrThreads, bool RemoveEmpty=false); std::vector<unsigned int> AssignJobs2Threads(unsigned int jobs, unsigned int nrThreads, bool RemoveEmpty=false);
std::vector<float> SplitString2Float(std::string str, std::string delimiter=","); std::vector<float> SplitString2Float(std::string str, std::string delimiter=",");
std::vector<double> SplitString2Double(std::string str, std::string delimiter=",");
#endif // USEFUL_H #endif // USEFUL_H