<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    JUST DO IT ~

    我只想當個程序員

    c++ c stl boost trim 函數

    c++ c stl boost  trim 函數


    參考:

    http://www.cplusplus.com/faq/sequences/strings/trim/

    What's the best way to trim std::string
    http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring

     

    其中這個方案我喜歡:

    #include <algorithm>
    #include <functional>
    #include <cctype>
    #include <locale>

    // trim from start
    static inline std::string &ltrim(std::string &s) {
            s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
            return s;
    }

    // trim from end
    static inline std::string &rtrim(std::string &s) {
            s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
            return s;
    }

    // trim from both ends
    static inline std::string &trim(std::string &s) {
            return ltrim(rtrim(s));
    }

     
    BOOST 方案 : 
    #include <boost/algorithm/string.hpp>
    using namespace std;
    using namespace boost::algorithm;
    
    string str1(" hello world! ");
    trim(str1);
    
    // str1 is now "hello world!"
    // Use trim_right() if only trailing whitespace is to be removed.
    最剪短方案:
    std::string s;
    s.erase(s.find_last_not_of(" \n\r\t")+1);
     

    posted on 2015-03-20 09:39 小高 閱讀(1920) 評論(0)  編輯  收藏 所屬分類: C

    導航

    <2015年3月>
    22232425262728
    1234567
    891011121314
    15161718192021
    22232425262728
    2930311234

    統計

    常用鏈接

    留言簿(3)

    隨筆分類(352)

    收藏夾(19)

    關注的blog

    手冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 91精品国产免费久久国语蜜臀 | 香蕉视频亚洲一级| 最近的免费中文字幕视频| 亚洲白色白色在线播放| 99re在线视频免费观看| 亚洲理论片在线观看| 亚洲天堂免费在线| 亚洲色大网站WWW永久网站| 永久免费av无码网站大全| 亚洲av日韩专区在线观看| 免费A级毛片无码A∨男男| 猫咪www免费人成网站| 亚洲一区二区高清| 久久国产精品免费网站| 亚洲精品在线电影| 日韩特黄特色大片免费视频| 特a级免费高清黄色片| 亚洲成a人片在线观看日本| 免费无码一区二区三区| 亚洲一卡2卡4卡5卡6卡在线99| 成年性羞羞视频免费观看无限| 青青青亚洲精品国产| 亚洲自偷自偷图片| 免费在线视频你懂的| 亚洲AV无码一区二区三区久久精品 | 亚洲AV无码无限在线观看不卡| 永久免费视频v片www| 曰韩无码AV片免费播放不卡| 亚洲狠狠久久综合一区77777| 日韩视频在线精品视频免费观看 | 国产精品亚洲片在线花蝴蝶| 最新亚洲成av人免费看| 日韩版码免费福利视频| 国产精品亚洲专区无码WEB| 亚洲精品自在在线观看| 在线观看无码AV网站永久免费 | 8090在线观看免费观看| 狼人大香伊蕉国产WWW亚洲| 亚洲国产精品久久久天堂| 毛片a级毛片免费播放下载 | 中文字幕无码精品亚洲资源网久久|