D
Diwa
Hi Guys,
Is there any better way than below to find an int in a string (e.g.
"30" in "KFStat30A")
// --------------------------------------------------------------
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
vector<string> strs ;
strs.push_back("KFStat30A");
strs.push_back("KFStat2A");
strs.push_back("555555");
strs.push_back("KKKKKK");
strs.push_back("KKKK555");
std::string str;
for (int i=0; i<strs.size(); i++)
{
str = "";
int beg = strs.find_first_of("0123456789");
if (beg != string::npos)
{
int end = strs.find_first_not_of("0123456789", beg);
str.assign(strs, beg, end-beg);
}
cout << strs << " " << str << "\n";
}
return 0;
}
// --------------------------------------------------------------
Thanks
-- Diwa
Is there any better way than below to find an int in a string (e.g.
"30" in "KFStat30A")
// --------------------------------------------------------------
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
vector<string> strs ;
strs.push_back("KFStat30A");
strs.push_back("KFStat2A");
strs.push_back("555555");
strs.push_back("KKKKKK");
strs.push_back("KKKK555");
std::string str;
for (int i=0; i<strs.size(); i++)
{
str = "";
int beg = strs.find_first_of("0123456789");
if (beg != string::npos)
{
int end = strs.find_first_not_of("0123456789", beg);
str.assign(strs, beg, end-beg);
}
cout << strs << " " << str << "\n";
}
return 0;
}
// --------------------------------------------------------------
Thanks
-- Diwa