Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

C/C++ API Documentation | 2026.1

# StrOps::Replace( StrBuf &, const StrPtr &, const StrPtr &, const StrPtr & )

Replace substrings in a `StrPtr` and store the result to a `StrBuf`.

Virtual? | No |
Class | `StrOps` |
Arguments | `StrBuf &o` | the output string
| `StrPtr &i` | the input string
| `StrBuf &s` | the substring to match
| `StrPtr &r` | the substring to replace `s`
Returns | `void` |

## Notes

This function reads the input string `i` and copies it to the output string `o`, after replacing each occurrence of the string `s` with string `r`.

## Example

Copy

    StrBuf i = StrBuf();
    i.Set( "PerForce is PerForce, of course, of course!" );

    StrBuf wrong, right;
    wrong.Set( "PerForce" );
    right.Set( "Perforce" );

    StrBuf o = StrBuf();

    StrOps::Replace( o, i, wrong, right );

    StrOps::Dump( o );

Executing the preceding code produces the following output:

    % a.out
    Perforce is Perforce, of course, of course!

Your search for returned results