this question has answer here:
- replace substring substring c++ 12 answers
i have function removes occurrences of sub-string c++ string. want insert spaces before or after removing every sub-string. function if given below:
void removesubstrs(string& s, string& p) { string::size_type n = p.length(); (string::size_type = s.find(p); != string::npos; = s.find(p)) s.erase(i, n); }
for example if input "azazblackazazberryaz", want output "black berry"....
if want this:
assume "-" space
input: "azazblackazazberryaz" , "az"
output: "--black--berry-"
then, may you:
void removesubstrs(string& s, string& p) { string::size_type n = p.length(); (string::size_type = s.find(p); != string::npos; = s.find(p)) { s.replace(i, n, 1, ' '); //or //s.erase(i, n); //s.inset(i, ' '); //add line } }
Comments
Post a Comment