String Replace in File
fc_str_replaceReplaces a unique string in a file with another. Useful for renaming functions, adding imports, or deleting lines when the target string appears exactly once. Returns an error if zero or multiple occurrences are found.
Instructions
Replaces a unique string in a file with another.
Args:
path (string): Path to the file
old_str (string): String to replace (must occur exactly once)
new_str (string): New string (empty = delete)
Returns:
Confirmation with context
IMPORTANT: old_str must occur EXACTLY once in the file! An error is returned for 0 or >1 occurrences.
Examples:
Rename function: old_str="def old_name", new_str="def new_name"
Add import: old_str="import os", new_str="import os\nimport sys"
Delete line: old_str="# TODO: remove this\n", new_str=""
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file | |
| old_str | Yes | String to replace (must be unique) | |
| new_str | No | New string (empty = delete) |