有没有办法如何删除所有非字母字符(即,.?!等),std::string而不删除捷克符号,如š?é??我试过用:
std::string FileHandler::removePunctuation(std::string word) {
for (std::string::iterator i = word.begin(); i != word.end(); i++) {
if (!isalpha(word.at(i - word.begin()))) {
word.erase(i);
i--;
}
}
return word;
}
Run Code Online (Sandbox Code Playgroud)
但它删除了捷克人物.
在最好的情况下,我也想toLowerCase用于那些符号.
您可以std::remove_if与以下一起使用erase:
#include <cctype>
#include <algorithm>
#include <string>
//...
std::wstring FileHandler::removePunctuation(std::wstring word)
{
word.erase(std::remove_if(word.begin(), word.end(),
[](char ch){ return !::iswalnum(ch); }), word.end());
return word;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2035 次 |
| 最近记录: |