美文网首页
c++ 中文字符分割

c++ 中文字符分割

作者: 思君颜如玉 | 来源:发表于2020-01-21 14:22 被阅读0次

utf-8
vector<string> Similarity::s2v(string t_str)
{
boost::regex re("\d+");
//setup converter
vector<string> wanted;
for(int i=0; i<t_str.length(); i++){

    char c = t_str[i];
    unsigned short b = 0x80;
    int head = 0;
    while((c & (b>>head)) != 0){
        head += 1;
    }
    if(head == 0)head = 1;
    string candiate = t_str.substr(i, head);
    //is number
    if(!wanted.empty()){
        if(boost::regex_match(candiate, re) && boost::regex_match(*(wanted.end()-1), re)) {
            *(wanted.end() - 1) = *(wanted.end() - 1) + candiate;
            continue;
        }
        bool repeat = 0;
        for(auto item : wanted){
            if(item == candiate){
                repeat = 1;
                break;
            }
        }
        if(repeat)
            continue;
    }
    wanted.push_back(candiate);
    i+=head-1;
}
return wanted;

}

相关文章

  • c++ 中文字符分割

    utf-8vector Similarity::s2v(string t_str){boost::regex r...

  • split分割字符串

    :字符串既有中文又有英文逗号 (2) 以 中文 或 英文 逗号分割字符串:字符串既有中文又有英文逗号 拓展:使用正...

  • std::wstring 字符串分割 split() 实现

    C++标准库里没有字符分割函数split(), 需要自己实现。 方法一#### 参考StackOverflow,写...

  • 使用boost::split_iterator进行字符串分割

    代码非常简单,实际上就是根据一个分割字符串组合,来返回分割后的字符串列表。在C++中,实际返回一个iterator...

  • C++ 读取txt,csv文件

    1、C++ 读取txt文件 2、C++ 读取csv文件附上一个分割字符串的功能函数,根据自己情况修改吧

  • 字符串分割-C++

  • C++字符串分割

    最近在研究C++,遇到一个问题需要将类似如下的字符串分割开:17;"_testCube##e17##13##Sma...

  • c++分割字符串

    1、find函数原型:size_t find ( const string& str, size_t pos = ...

  • C++分割字符串

    C++的string默认没有split函数,但是split函数又是如此常用,今天在网上查资料学习一下。方法一:使用...

  • C++字符串分割

    很多人对C++的刻板印象是C++不适合处理字符串,其实C++也是有很方便的函数可以处理字符串的。下面我们来讲一下C...

网友评论

      本文标题:c++ 中文字符分割

      本文链接:https://www.haomeiwen.com/subject/ikjecctx.html