最新下载
热门教程
- 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; } |
相关文章
- 王国之泪古栗欧克王怎么打 07-02
- 无畏契约炼狱莲华古城怎么守A 07-02
- 原神深渊第一层怎么打 07-02
- 新三国志曹操传赵云救公孙关卡攻略 07-02
- ps怎样给美女照片添加好看的蓝色美瞳效果? 07-02
- 区块链:Gate.io手机App快捷交易买币/卖币操作步骤教程 07-02