C++ handles Chinese symbols for example illustration
- 2020-05-12 02:53:34
- OfStack
C++ handles Chinese symbols
English symbols are replaced by English commas
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;
}
Replace the Chinese comma with the English comma
processChinesePunctuation(string& tag)
{
string u8comma = u8" . ";
for (int i = 0; i < tag.size() - u8comma.size() + 1; i++)
{
bool find = true;
// Finding Spaces depends on UTF-8 The characteristics of the
for (int j = 0; j < u8comma.size(); j++)
{
if (tag[i + j] != u8comma[j])
{
find = false;
break;
}
}
if (find)
{
// Replace with ,
tag[i] = ',';
auto it = tag.begin();
it += i + 1;
for (int j = 1; j < u8comma.size(); j++)
it = tag.erase(it);
}
}
return;
}
Thank you for reading, I hope to help you, thank you for your support of this site!