C++ 处理中文符号实例详解
2017-01-17 14:21
417 查看
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; }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- 处理JSP中文跨页面间传参乱码的问题有两种方法实现方法(每个搞JSP的最常遇到的问题之一) 实例版:)
- VC/C++的中文字符处理方式
- 关于C++中文字符的处理
- cmd批处理常用符号详解
- 用思维导图和实例学习C++之一——字符串处理
- Java处理中文话问题详解
- cmd批处理常用符号详解
- WMI via C++: 一个C++风格的复杂性处理实例
- 批处理常用符号详解综合教程
- C++中文字符的处理
- VC/C++的中文字符处理方式(一)
- 处理 C++ 项目中的 IntelliSense 失败:输入类实例后,不能显示其成员几成员函数问题解决
- [转载+总结]关于C++中文字符的处理
- php处理字符串,判断是否含有特殊符号,非中文,数字,字符
- 关于C++中文字符的处理
- 实例详解C++友元
- VC/C++的中文字符处理方式
- Struts实例详解2--中文乱码
- 用思维导图和实例学习C++之一——字符串处理
- 今天发现了c++符号重载的一个非常实用的使用实例。