Регулярные выражения, поиск и замена:
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| #include <iostream>
#include <string>
#include <boost/regex.hpp>
std::string erase_spaces(const std::string& s)
{
boost::regex reg("\\s{2,}");
return std::string(boost::regex_replace(s, reg, " "));
}
int main()
{
std::cout<<erase_spaces("Some text text other text ")<<"\n";
std::cout<<erase_spaces("Another text")<<"\n";
std::cout<<"\n";
return 0;
} |
|