如何在字符串中查找字符,如果它们与特定字符匹配则删除它们?

时间:2017-07-12 06:45:05

标签: c++11

/ *我必须根据if / else if条件中的字符找到字符并删除它们。如果条件* /

,我很难进入其他地方
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <string>
using namespace std;

int main() {
    int fut = 0, spd =0;
    std::string symbol = "PGSh/d TWOGK h/d"; //it will contain either 'h/d' or '/'

    std::string str = "h/d";
    std::string str1 = "/";
if(symbol.find(str))   //if it finds "h/d" then it belongs to future
{
    ++fut;    //even one count is enough
    boost::erase_all(symbol, "h/d");
    std::cout<<"Future Instrument "<<std::endl;
}
else if(symbol.find(str1)) //if it finds "/" then it belongs to spread
{
    ++spd;    //even one count is enough
    boost::erase_all(symbol, "//");
    std::cout<<"Spread Instrument "<<std::endl;
}
boost::erase_all(symbol, " ");
boost::to_upper(symbol);
std::cout<<symbol<<std::endl;
return 0;
}

0 个答案:

没有答案