最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C++ 处理中文符号实例详解
时间:2022-06-25 04:40:35 编辑:袖梨 来源:一聚教程网
C++ 处理中文符号
英文符号替换为英文逗号
代码如下 | 复制代码 |
processPunctuation(string& tag) { std::set punctuation_set.insert(' '); punctuation_set.insert('t'); punctuation_set.insert('');
for(inti=0; i< tag.size(); i++) { if(punctuation_set.find(tag[i]) != punctuation_set.end()) { tag[i] =',' } } return; } |
中文逗号替换为英文逗号
代码如下 | 复制代码 |
processChinesePunctuation(string& tag) { string u8comma = u8","; for(inti = 0; i < tag.size() - u8comma.size() + 1; i++) { boolfind =true; // 查找空格依赖于 UTF-8 的特性 for(intj = 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(intj = 1; j < u8comma.size(); j++) it = tag.erase(it); } } return; } |
相关文章
- 光与夜之恋陪伴商店有什么更新 05-13
- 《塞尔达传说王国之泪》新手开荒心得分享 有什么心得? 05-13
- 热币网交易所官网版 05-13
- 无期迷途夜色将洇监察密令怎么玩 加洛法诺监察密令活动介绍 05-13
- 时空中的绘旅人炙情拭色礼包怎么样 炙情拭色特别礼包介绍 05-13
- 光与夜之恋陪伴商店有什么更新 光与夜之恋陪伴商店限时上新介绍 05-13