最新下载
热门教程
- 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; } |
相关文章
- 开放空间宁蒙有什么技能 09-15
- 小鸡舰队出击天空首领活动怎么玩 09-15
- 魔法工艺套装如何解锁使用 09-15
- 三国群英传策定九州资源地有什么打法技巧 09-15
- 下一站江湖2马夫人任务怎么完成 09-15
- 小鸡舰队出击终焉灵王队伍如何搭配 09-15