WordFindAndReplaceAgentTools Class
Provides agent tools for text search and replacement operations in Word documents. Handles finding and replacing text with support for case sensitivity and whole word matching.
Inherited Members
Namespace: Syncfusion.AI.AgentTools.Word
Assembly: Syncfusion.DocumentSDK.AI.AgentTools.dll
Syntax
public class WordFindAndReplaceAgentTools : AgentToolBase<WordDocument>
Constructors
WordFindAndReplaceAgentTools(DocumentStorageManager)
Initializes a new instance of the WordFindAndReplaceAgentTools class (Mode 2 — DocumentStorage).
Declaration
public WordFindAndReplaceAgentTools(DocumentStorageManager manager)
Parameters
| Type | Name | Description |
|---|---|---|
| DocumentStorageManager | manager | The document storage manager. |
WordFindAndReplaceAgentTools(WordDocumentManager)
Initializes a new instance of the WordFindAndReplaceAgentTools class (Mode 1 — InMemory).
Declaration
public WordFindAndReplaceAgentTools(WordDocumentManager manager)
Parameters
| Type | Name | Description |
|---|---|---|
| WordDocumentManager | manager | The document manager for managing Word documents. |
Methods
FindAndReplace(String, String[], String[], Boolean, Boolean, Boolean, String)
Finds and replaces all occurrences of one or more specified texts in the Word document.
Declaration
[Tool(Name = "FindAndReplace", Description = "Finds all occurrences of one or more specified texts in the Word document and replaces each with the corresponding replacement text in a single pass on the same document. Accepts arrays so multiple placeholders can be replaced at once without reopening the file. documentIdOrFilePath: The document ID (InMemory mode) or input file path (DocumentStorage mode).")]
public AgentToolResult FindAndReplace([ToolParameter(Description = "The document ID (InMemory mode) or input file path (DocumentStorage mode)")] string documentIdOrFilePath, [ToolParameter(Description = "Array of texts to search for")] string[] findTexts, [ToolParameter(Description = "Array of replacement texts corresponding to each find text")] string[] replaceTexts, [ToolParameter(Description = "Whether to match case (true/false)")] bool matchCase = false, [ToolParameter(Description = "Whether to match whole words only (true/false)")] bool wholeWord = false, [ToolParameter(Description = "Whether to find and replace first occurrence or all occurrences (true/false)")] bool replaceFirst = false, [ToolParameter(Description = "Output file path for saving the result (DocumentStorage mode only).")] string outputFilePath = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | documentIdOrFilePath | The document ID (InMemory mode) or input file path (DocumentStorage mode). |
| System.String[] | findTexts | Array of texts to search for. |
| System.String[] | replaceTexts | Array of replacement texts corresponding to each find text. |
| System.Boolean | matchCase | Indicates whether the search should be case-sensitive. |
| System.Boolean | wholeWord | Indicates whether only whole words should be matched. |
| System.Boolean | replaceFirst | Indicates whether to replace only the first occurrence. |
| System.String | outputFilePath | Output file path for saving the result (DocumentStorage mode only). |
Returns
| Type | Description |
|---|---|
| AgentToolResult | Result indicating whether the find-and-replace operation succeeded or failed. |
FindAndReplaceByPattern(String, String, String, Boolean, String)
Finds and replaces occurrences of the specified regex pattern in the Word document.
Declaration
[Tool(Name = "FindAndReplaceByPattern", Description = "Finds and replaces first occurrence of the specified pattern in the Word document. Returns a count of replaced text.")]
public AgentToolResult FindAndReplaceByPattern([ToolParameter(Description = "The document ID (InMemory mode) or input file path (DocumentStorage mode)")] string documentIdOrFilePath, [ToolParameter(Description = "The regex pattern to match text (e.g., '{[A-Za-z]+}' to match placeholders like {Name}, {Date})")] string findWhat, [ToolParameter(Description = "The replacement text")] string replaceText, [ToolParameter(Description = "Whether to find and replace first occurence or all occurence (true/false)")] bool replaceFirst = false, [ToolParameter(Description = "Output file path for saving the result (DocumentStorage mode only).")] string outputFilePath = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | documentIdOrFilePath | The document ID (InMemory mode) or input file path (DocumentStorage mode). |
| System.String | findWhat | The regular expression pattern used to match text (for example, '{[A-Za-z]+}' to match placeholders like {Name} or {Date}). |
| System.String | replaceText | The text used to replace the matched content. |
| System.Boolean | replaceFirst | Specifies whether to replace only the first match. |
| System.String | outputFilePath | Output file path for saving the result (DocumentStorage mode only). |
Returns
| Type | Description |
|---|---|
| AgentToolResult | Result indicating the number of replacements performed. |