乐业成就人生

std::string 的几种用法

toupper, tolower
transform(s.begin(), s.end(), s.begin(), toupper);

transform(s.begin(), s.end(), s.begin(), tolower);

------------------------------------------------------------------------
trim

    s.erase(0, s.find_first_not_of(" \n"));

    s.erase(s.find_last_not_of('' '') + 1);

-----------------------------------------------------------------------
erase

   s.erase(remove_if(s.begin(),s.end(),
        bind2nd(equal_to<char>(), '' '')),
    s.end());

-----------------------------------------------------------------------
replace
     s.replace(s.find(sub), sub.size(), strRep);
  -----------------------------------------------------------------------
startwith, endwith
     bool startwith = s.compare(0, head.size(), head) == 0;
    bool endwith = s.compare(s.size() - tail.size(), tail.size(), tail) == 0;

------------------------------------------------------------------------
toint, todouble, tobool...

    atoi(s.c_str());    
    stringstream(s) >> ii;    
    atof(sd.c_str());

------------------------------------------------------------------------

posted on 2009-05-12 09:32  阿郑  阅读(603)  评论(0)    收藏  举报