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; // 查找空格依賴于 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)文章
C++中的動(dòng)態(tài)規(guī)劃子序列問題分析探討
可能有些讀者有接觸過動(dòng)態(tài)規(guī)劃,可能也有一些讀者以前完全不知道動(dòng)態(tài)規(guī)劃這個(gè)東西,別擔(dān)心,我這篇文章會(huì)為讀者做一個(gè)入門,好讓讀者掌握這個(gè)重要的知識(shí)點(diǎn)2023-03-03C語言程序設(shè)計(jì)50例(經(jīng)典收藏)
本篇文章是對(duì)C語言程序設(shè)計(jì)的50個(gè)小案例進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06Matlab實(shí)現(xiàn)別踩白塊小游戲的示例代碼
別踩白塊是一款音樂類休閑游戲,游戲的玩法不難,只需跟著音樂的節(jié)奏點(diǎn)中對(duì)的方塊即可。本文將用Matlab實(shí)現(xiàn)這一經(jīng)典游戲,感興趣的可以了解一下2022-03-03