Hello, there is a string

string str="go hi . uyyuer"; 

How can you find a character in this line, let's say "." and then copy it?

As a result, to get this:

 str="go hi .. uyyuer"; 

Thank.

    1 answer 1

     str.insert (str.find("."), "."); 

    PS General option:

     for (int i = 0; i < str.length()-1; i++) if (str.at(i) == '.') str.insert (i++, "."); 

    It is possible to try through STL somehow.

    • Generally it is true, and if there are many such points? how to be? - Alerr
    • Added a general version - skegg
    • for some reason it adds to the 1st ..., it turns out this text .... ... texr - Alerr
    • Thank!!! I myself was wrong first ... - Alerr