删除字符串c++开头和结尾的标点符号
Remove punctuation from beginning and end of string c++
是否有一种方法可以在字符串的开头和结尾删除标点符号,而只留下缩写和所有格?
e。G "!wow!"会变成"wow",而"can't"会保留"can't"
您可以使用boost::trim_if
:
std::string a = "!wow!";
boost::trim_if(a, [](char c) { return std::ispunct(c); });
std::cout << a << 'n';
输出:
wow