Searching and replacing all occurrence of a string in a char array c++ -


i have char array , want find positions of specific substring , replace substring different.

for example:

char [35] = "the boy stole cup table."; 

1. want print out every position "the" is. have found functions find finds first position of want. tried using loop did not work out.

  1. i want replace occurence of "the" "that" can show me how achieve this. , working char array , not string class.

try function . think work.

void find_and_replace(string& source, string const& find, string const& replace) {     for(string::size_type = 0; (i = source.find(find, i)) != string::npos;)     {         source.replace(i, find.length(), replace);         += replace.length();     } }      content = "this c++ programming";     find_and_replace(content, "c++", "java"); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -