Quantcast
Channel: C++博客-天使的白骨-随笔分类-C++ lisp perl ruby python
Viewing all articles
Browse latest Browse all 15

C++截取中文,费了点时间才搞出来,代码不多,大家有需要的不用客气,复制粘贴就好。参考了别人的,但是他的代码有错误,不能直接使用

$
0
0
    std::string textStr = element.text;
    std::string lines;
    int len = 40;
    if(element.text.length() > len){
        for(int cur = 0; cur < len;){
            char t = textStr[cur];
            if((t&0xE0) == 0xE0){    //3byte
                lines = lines + t + textStr[cur+1] + textStr[cur+2];
                cur += 3;
            }else if((t & 0xC0) == 0xC0){//2byte
                lines = lines + t + textStr[cur+1];
                cur += 2;
            }else { //1byte
                lines = lines + t;
                cur += 1;
            }
        }
        textStr = lines + "";
        CCLog("streaming text:%s", lines.c_str());
    }


何清龙 2013-10-09 20:55 发表评论

Viewing all articles
Browse latest Browse all 15

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>