雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C++ 處理中文符號實例詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊:

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


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

上一篇:Species Tree 利用HashTable實現(xiàn)實例代碼

欄    目:C語言

下一篇:c# 實現(xiàn)獲取漢字十六進制Unicode編碼字符串的實例

本文標(biāo)題:C++ 處理中文符號實例詳解

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/1787.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有