C++,
pasted
on Dec 9:
|
#include <iostream>
#include <cctype>
#include <string>
//удаление слова
void str_remove(std::string& s, const std::string& w, bool all = true){
std::string::size_type p = 0;
while((p = s.find(w, p)) != std::string::npos){
if((p == 0 || !isalpha(s[p - 1])) &&
(p + w.length() >= s.length() || !isalpha(s[p + w.length()]))){
s.erase(p, w.length());
if(! all)
break;
} else
p += w.length();
}
}
int main(void){
std::string s = "APL, AAPL, (APL) APLL, OAPLO APL";
std::string w = "APL";
std::cout << s << std::endl;
str_remove(s, w);
std::cout << s << std::endl;
//вставка
s.insert(5, "* * * GAME * * *");
std::cout << s << std::endl;
return 0;
}
|
Output:
|
APL, AAPL, (APL) APLL, OAPLO APL
, AAPL, () APLL, OAPLO
, AAP* * * GAME * * *L, () APLL, OAPLO
|
|