欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++ 處理中文符號(hào)實(shí)例詳解

 更新時(shí)間:2017年01月17日 14:21:57   投稿:lqh  
這篇文章主要介紹了C++ 處理中文符號(hào)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

C++ 處理中文符號(hào)

英文符號(hào)替換為英文逗號(hào)

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;
}

中文逗號(hào)替換為英文逗號(hào)

processChinesePunctuation(string& tag)
{
  string u8comma = u8",";
  for (int i = 0; i < tag.size() - u8comma.size() + 1; i++)
  {
    bool find = true;
    // 查找空格依賴(lài)于 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;
}


感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論