String Replace in File
fc_str_replaceReplace a unique string in a file with a new string. Ensures the old string occurs exactly once, returning an error for zero or multiple occurrences.
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 | |
| new_str | No | New string (empty = delete) | |
| old_str | Yes | String to replace (must be unique) |