C ++从String中删除标点符号 [英] C++ Remove punctuation from String
本文介绍了C ++从String中删除标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,我想删除所有的标点符号。我怎么做?我做了一些研究,发现人们使用ispunct()函数(我试过),但我似乎无法让它在我的代码工作。任何人都有任何想法?
I got a string and I want to remove all the punctuations from it. How do I do that? I did some research and found that people use the ispunct() function (I tried that), but I cant seem to get it to work in my code. Anyone got any ideas?
#include <string>
int main() {
string text = "this. is my string. it's here."
if (ispunct(text))
text.erase();
return 0;
}
推荐答案
size_t found = text.find('.');
text.erase(found, 1);
这篇关于C ++从String中删除标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文