C++ 处理中文符号实例详解分享

—-想了解C++ 处理中文符号实例详解分享的全部内容且更多的C语言教程关注<计算机技术网(www.ctvol.com)!!>

C++ 处理中文符号

英文符号替换为英文逗号

  processPunctuation(string& tag)  {    std::set<char> punctuation_set;    punctuation_set.insert(' ');    punctuation_set.insert('t');    punctuation_set.insert(';');      for (int i=0; i< tag.size(); i++) {      if (punctuation_set.find(tag[i]) != punctuation_set.end())       {        tag[i] = ',';      }    }    return;  }    

中文逗号替换为英文逗号

  processChinesePunctuation(string& tag)  {    string u8comma = u8",";    for (int i = 0; i < tag.size() - u8comma.size() + 1; i++)    {      bool find = true;      // 查找空格依赖于 UTF-8 的特性      for (int j = 0; j < u8comma.size(); j++)      {        if (tag[i + j] != u8comma[j])        {          find = false;          break;        }      }          if (find)      {        // 替换为 ,        tag[i] = ',';        auto it = tag.begin();        it += i + 1;        for (int j = 1; j < u8comma.size(); j++)          it = tag.erase(it);      }    }    return;  }      

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/487773.html

(0)
上一篇 2020年11月11日
下一篇 2020年11月12日

精彩推荐