agentleFS
aspose-wordsaspose-words/agentic-net-examples/find-and-replace/AGENTS.md

agentic-net-examples / find-and-replace

AGENTS.md4 starsChanged 3 months agoMITView on GitHub

Verified C# examples for find-and-replace scenarios in Aspose.Words for .NET

The file

We split this AGENTS.md into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use native Range.Replace APIs directly.

    line 17
  2. Very specific:

    Use FindReplaceOptions and IReplacingCallback only through documented Aspose.Words APIs.

    line 19
  3. Very specific:

    Use Newtonsoft.Json for JSON reporting tasks and Aspose.Drawing instead of System.Drawing when drawing-related types are needed.

    line 20
  4. Distinctive:

    Use the simplest workflow that satisfies the task.

    line 32
  5. Distinctive:

    When replacing a file, prefer the latest verified publish-ready version rather than a merely compiling draft.

    line 422
  6. Distinctive:

    Keep examples standalone, bootstrap missing inputs locally, and prefer documented Aspose APIs over speculative shortcuts.

    line 423

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md - Find and Replace

Purpose

This folder is a live, curated example set for Find and Replace scenarios. Treat every .cs file as a standalone console application. The goal is correct, warning-free examples that use documented Aspose APIs and match the original task intent.

Non-negotiable conventions

  • Use native Range.Replace APIs directly.
  • Bootstrap local source documents, files, streams, or folders whenever the task implies an existing source.
  • Use FindReplaceOptions and IReplacingCallback only through documented Aspose.Words APIs.
  • Use Newtonsoft.Json for JSON reporting tasks and Aspose.Drawing instead of System.Drawing when drawing-related types are needed.
  • For metacharacter tasks, create real document control structures rather than plain literal backslash sequences.
  • Guard maybe-null values to avoid nullable-reference warnings such as CS8600, CS8602, and CS8604.

Recommended workflow selection

  • Plain Replace workflow: 41 examples
  • Formatting Aware Replace workflow: 7 examples
  • Regex Replace workflow: 7 examples
  • Callback Reporting workflow: 6 examples
  • Input Bootstrap workflow: 2 examples

Use the simplest workflow that satisfies the task.

Validation priorities

  1. The code must compile and run without manual input.
  2. API usage must be supported by the configured package versions.
  3. Exported outputs must actually be written by the example.
  4. Validation scenarios must inspect only the behavior requested by the task.
  5. Examples that depend on files, folders, streams, images, or data should bootstrap those inputs locally during the example run.

File-to-task reference

  • load-a-docx-file-into-a-document-object-and-replace-all-literal-string-occurrences.cs
    • Task: Load a DOCX file into a Document object and replace all literal string occurrences.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • perform-a-case-sensitive-replace-using-findreplaceoptions-with-matchcase-enabled-on-the-lo.cs
    • Task: Perform a case-sensitive replace using FindReplaceOptions with MatchCase enabled on the loaded document.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-whole-words-only-by-setting-findreplaceoptions-matchwholeword-to-true-during-repla.cs
    • Task: Replace whole words only by setting FindReplaceOptions.MatchWholeWord to true during replacement.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • execute-a-regular-expression-replace-that-converts-dates-from-mm-dd-yyyy-to-yyyy-mm-dd-for.cs
    • Task: Execute a regular expression replace that converts dates from MM-DD-YYYY to YYYY-MM-DD format.
    • Workflow: formatting-aware-replace
    • Outputs: docx
    • Selected engine: mcp
  • apply-metacharacters-in-the-replacement-string-to-insert-line-breaks-after-each-replaced-p.cs
    • Task: Apply metacharacters in the replacement string to insert line breaks after each replaced paragraph.
    • Workflow: regex-replace
    • Outputs: docx
    • Selected engine: mcp
  • search-and-replace-text-within-header-sections-by-accessing-the-document-s-headersfooters.cs
    • Task: Search and replace text within header sections by accessing the document's HeadersFooters collection.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • search-and-replace-text-within-footer-sections-while-preserving-existing-page-numbers-usin.cs
    • Task: Search and replace text within footer sections while preserving existing page numbers using FindReplaceOptions.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • ignore-field-codes-during-replacement-by-enabling-findreplaceoptions-ignorefields-before-c.cs
    • Task: Ignore field codes during replacement by enabling FindReplaceOptions.IgnoreFields before calling Replace.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • implement-a-custom-replaceevaluator-delegate-to-replace-only-words-longer-than-ten-charact.cs
    • Task: Implement a custom ReplaceEvaluator delegate to replace only words longer than ten characters.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • count-the-number-of-replacements-performed-by-storing-the-integer-result-returned-from-the.cs
    • Task: Count the number of replacements performed by storing the integer result returned from the Replace method.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • chain-multiple-replace-calls-to-sequentially-replace-email-addresses-phone-numbers-and-url.cs
    • Task: Chain multiple Replace calls to sequentially replace email addresses, phone numbers, and URLs in the document.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • combine-findreplaceoptions-with-documentbuilder-to-insert-dynamic-content-after-each-succe.cs
    • Task: Combine FindReplaceOptions with DocumentBuilder to insert dynamic content after each successful replacement.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • enable-regex-mode-by-setting-findreplaceoptions-useregularexpressions-to-true-for-pattern.cs
    • Task: Enable regex mode by setting FindReplaceOptions.UseRegularExpressions to true for pattern-based replacements.
    • Workflow: regex-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-tab-characters-with-four-spaces-using-a-regular-expression-pattern-matching-the-t.cs
    • Task: Replace tab characters with four spaces using a regular expression pattern matching the \t escape sequence.
    • Workflow: regex-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-placeholder-tokens-like-name-with-actual-values-using-a-dictionary-inside-a-replac.cs
    • Task: Replace placeholder tokens like {{Name}} with actual values using a dictionary inside a ReplaceEvaluator.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • execute-a-case-insensitive-replace-that-changes-all-instances-of-color-to-colour-throughou.cs
    • Task: Execute a case-insensitive replace that changes all instances of ‘color' to ‘colour' throughout the document.
    • Workflow: formatting-aware-replace
    • Outputs: docx
    • Selected engine: mcp
  • apply-whole-word-matching-to-avoid-partial-replacements-inside-longer-words-such-as-catalo.cs
    • Task: Apply whole-word matching to avoid partial replacements inside longer words such as ‘catalogue'.
    • Workflow: callback-reporting
    • Outputs: docx
    • Selected engine: mcp
  • replace-multiple-line-break-sequences-with-a-single-paragraph-break-using-the-metacharacte.cs
    • Task: Replace multiple line break sequences with a single paragraph break using the metacharacter \n in the replacement.
    • Workflow: regex-replace
    • Outputs: docx
    • Selected engine: mcp
  • perform-find-and-replace-on-a-document-loaded-from-a-memory-stream-without-writing-to-disk.cs
    • Task: Perform find and replace on a document loaded from a memory stream without writing to disk.
    • Workflow: input-bootstrap
    • Outputs: docx
    • Selected engine: mcp
  • configure-findreplaceoptions-replacingcallback-to-log-each-replacement-occurrence-to-a-cus.cs
    • Task: Configure FindReplaceOptions.ReplacingCallback to log each replacement occurrence to a custom logger.
    • Workflow: callback-reporting
    • Outputs: docx
    • Selected engine: mcp
  • use-a-regular-expression-to-locate-and-replace-all-html-tags-embedded-in-the-document-text.cs
    • Task: Use a regular expression to locate and replace all HTML tags embedded in the document text.
    • Workflow: input-bootstrap
    • Outputs: html
    • Selected engine: mcp
  • update-the-copyright-year-in-headers-and-footers-by-replacing-the-old-year-with-the-curren.cs
    • Task: Update the copyright year in headers and footers by replacing the old year with the current year.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • set-matchcase-false-and-matchwholeword-true-to-replace-whole-words-case-insensitively-acro.cs
    • Task: Set MatchCase false and MatchWholeWord true to replace whole words case-insensitively across the document.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • implement-a-progress-reporter-that-receives-the-replacement-count-after-each-replace-call.cs
    • Task: Implement a progress reporter that receives the replacement count after each Replace call.
    • Workflow: callback-reporting
    • Outputs: docx
    • Selected engine: mcp
  • replace-unicode-em-dashes-with-standard-hyphens-using-a-regular-expression-for-the-dash-ch.cs
    • Task: Replace Unicode em dashes with standard hyphens using a regular expression for the dash character.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • mask-phone-numbers-by-finding-them-with-a-regular-expression-and-replacing-with-asterisks.cs
    • Task: Mask phone numbers by finding them with a regular expression and replacing with asterisks for privacy.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • apply-findreplaceoptions-ignorefields-to-skip-replacing-field-result-texts-while-updating.cs
    • Task: Apply FindReplaceOptions.IgnoreFields to skip replacing field result texts while updating field codes.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • add-a-prefix-to-each-matched-word-using-a-custom-replaceevaluator-delegate-during-replacem.cs
    • Task: Add a prefix to each matched word using a custom ReplaceEvaluator delegate during replacement.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-deprecated-terms-with-new-equivalents-across-multiple-languages-using-culture-spec.cs
    • Task: Replace deprecated terms with new equivalents across multiple languages using culture-specific regular expressions.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • perform-conditional-replacement-that-only-changes-text-appearing-after-a-specific-heading.cs
    • Task: Perform conditional replacement that only changes text appearing after a specific heading using a callback.
    • Workflow: callback-reporting
    • Outputs: docx
    • Selected engine: mcp
  • replace-double-spaces-with-a-single-space-throughout-the-document-using-a-simple-regular-e.cs
    • Task: Replace double spaces with a single space throughout the document using a simple regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • add-a-suffix-to-each-matched-numeric-value-using-a-custom-replaceevaluator-during-the-repl.cs
    • Task: Add a suffix to each matched numeric value using a custom ReplaceEvaluator during the replace operation.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-language-code-tags-with-full-language-names-using-a-regular-expression-for-accurat.cs
    • Task: Replace language code tags with full language names using a regular expression for accurate localization.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-placeholder-merge-fields-with-actual-data-by-evaluating-each-field-inside-a-replac.cs
    • Task: Replace placeholder merge fields with actual data by evaluating each field inside a ReplaceEvaluator delegate.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-the-word-foo-only-when-it-appears-at-the-start-of-a-paragraph-using-a-custom-evalu.cs
    • Task: Replace the word ‘foo' only when it appears at the start of a paragraph using a custom evaluator.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-the-first-page-header-differently-from-other-headers-by-checking-section-propertie.cs
    • Task: Replace the first page header differently from other headers by checking section properties during replacement.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • insert-a-page-break-after-each-replaced-heading-using-the-metacharacter-f-in-the-replaceme.cs
    • Task: Insert a page break after each replaced heading using the metacharacter \f in the replacement string.
    • Workflow: regex-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-color-names-with-their-hexadecimal-representations-using-a-regular-expression-for.cs
    • Task: Replace color names with their hexadecimal representations using a regular expression for color conversion.
    • Workflow: formatting-aware-replace
    • Outputs: docx
    • Selected engine: mcp
  • update-version-numbers-from-1-0-0-to-2-0-0-across-the-document-using-a-regular-expression.cs
    • Task: Update version numbers from 1.0.0 to 2.0.0 across the document using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-a-custom-delimiter-with-a-comma-while-preserving-surrounding-whitespace-using-a-re.cs
    • Task: Replace a custom delimiter with a comma while preserving surrounding whitespace using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • mask-email-addresses-by-locating-them-with-a-regular-expression-and-replacing-with-a-maske.cs
    • Task: Mask email addresses by locating them with a regular expression and replacing with a masked version.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • expand-macro-names-to-their-full-code-using-a-custom-replaceevaluator-delegate-during-repl.cs
    • Task: Expand macro names to their full code using a custom ReplaceEvaluator delegate during replacement.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • convert-date-strings-from-january-1-2020-to-01-01-2020-using-a-regular-expression.cs
    • Task: Convert date strings from ‘January 1, 2020' to ‘01/01/2020' using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-abbreviations-with-their-full-forms-while-preserving-surrounding-punctuation-using.cs
    • Task: Replace abbreviations with their full forms while preserving surrounding punctuation using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-placeholders-surrounded-by-double-brackets-with-values-from-a-json-configuration-f.cs
    • Task: Replace placeholders surrounded by double brackets with values from a JSON configuration file using a callback.
    • Workflow: callback-reporting
    • Outputs: json
    • Selected engine: mcp
  • replace-text-in-headers-containing-a-specific-keyword-while-leaving-other-headers-unchange.cs
    • Task: Replace text in headers containing a specific keyword while leaving other headers unchanged.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • convert-all-uppercase-words-to-title-case-using-a-custom-replaceevaluator-during-the-repla.cs
    • Task: Convert all uppercase words to title case using a custom ReplaceEvaluator during the replacement process.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-a-specific-bullet-character-with-a-different-bullet-style-throughout-the-document.cs
    • Task: Replace a specific bullet character with a different bullet style throughout the document using a regular expression.
    • Workflow: formatting-aware-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-a-custom-tag-attribute-value-across-the-entire-document-using-a-regular-expression.cs
    • Task: Replace a custom tag attribute value across the entire document using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • change-url-scheme-from-http-to-https-while-preserving-the-rest-of-each-hyperlink-using-a-r.cs
    • Task: Change URL scheme from http to https while preserving the rest of each hyperlink using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • convert-markdown-style-headings-to-word-heading-styles-throughout-the-document-using-a-reg.cs
    • Task: Convert markdown style headings to Word heading styles throughout the document using a regular expression.
    • Workflow: formatting-aware-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-the-copyright-symbol-with-the-unicode-character-using-a-regular-expression.cs
    • Task: Replace the copyright symbol with the Unicode © character using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • insert-a-page-number-field-after-each-replaced-heading-using-documentbuilder-for-automatic.cs
    • Task: Insert a page number field after each replaced heading using DocumentBuilder for automatic numbering.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-numeric-formats-like-1-234-56-with-a-localized-format-using-a-regular-expression.cs
    • Task: Replace numeric formats like 1,234.56 with a localized format using a regular expression.
    • Workflow: formatting-aware-replace
    • Outputs: docx
    • Selected engine: mcp
  • add-a-hyperlink-to-each-replaced-email-address-using-documentbuilder-during-the-replacemen.cs
    • Task: Add a hyperlink to each replaced email address using DocumentBuilder during the replacement operation.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: existing_repo
  • ignore-case-and-match-whole-words-when-updating-product-names-across-the-document-using-fi.cs
    • Task: Ignore case and match whole words when updating product names across the document using FindReplaceOptions.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-placeholders-surrounded-by-percent-signs-with-environment-variable-values-using-a.cs
    • Task: Replace placeholders surrounded by percent signs with environment variable values using a custom callback.
    • Workflow: callback-reporting
    • Outputs: docx
    • Selected engine: mcp
  • replace-multiple-consecutive-spaces-with-a-single-space-throughout-the-document-using-a-re.cs
    • Task: Replace multiple consecutive spaces with a single space throughout the document using a regular expression.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • add-a-custom-style-to-each-replaced-paragraph-using-documentbuilder-during-the-replacement.cs
    • Task: Add a custom style to each replaced paragraph using DocumentBuilder during the replacement process.
    • Workflow: formatting-aware-replace
    • Outputs: docx
    • Selected engine: mcp
  • standardize-date-range-patterns-to-a-unified-format-across-the-document-using-a-regular-ex.cs
    • Task: Standardize date range patterns to a unified format across the document using a regular expression.
    • Workflow: regex-replace
    • Outputs: docx
    • Selected engine: mcp
  • insert-a-table-of-figures-after-each-replaced-figure-caption-using-documentbuilder-for-aut.cs
    • Task: Insert a table of figures after each replaced figure caption using DocumentBuilder for automatic generation.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: mcp
  • use-a-custom-replaceevaluator-to-replace-only-the-first-occurrence-of-a-pattern-in-each-se.cs
    • Task: Use a custom ReplaceEvaluator to replace only the first occurrence of a pattern in each section.
    • Workflow: regex-replace
    • Outputs: docx
    • Selected engine: mcp
  • replace-a-placeholder-with-a-generated-qr-code-image-using-documentbuilder-during-the-repl.cs
    • Task: Replace a placeholder with a generated QR code image using DocumentBuilder during the replacement.
    • Workflow: plain-replace
    • Outputs: docx
    • Selected engine: existing_repo

Common failure patterns and preferred agent fixes

  • Invented find-replace APIs
    • Symptom: Code tries to use unsupported helpers such as Document.ReplaceAll or Paragraph.Replace.
    • Preferred fix: Use Document.Range.Replace with supported FindReplaceOptions and callback APIs only.
  • Callback misuse
    • Symptom: Custom replacement logic fails because IReplacingCallback or ReplacingArgs are used incorrectly.
    • Preferred fix: Implement IReplacingCallback with the documented Replacing method and assign it through FindReplaceOptions.ReplacingCallback.
  • Metacharacter source content mismatch
    • Symptom: Line-break or metacharacter replacement finds no matches because the source document was built with plain literal text instead of real control structures.
    • Preferred fix: Create real line breaks or control characters in the source document and validate that Range.Replace returns a replacement count greater than zero.
  • Invalid formatting insertion
    • Symptom: Replacement logic inserts formatted content into invalid node parents or assumes every match belongs to a single Run.
    • Preferred fix: Use supported run, font, paragraph, or builder logic and preserve valid parent-child insertion structure.
  • Drawing ambiguity
    • Symptom: Compile errors caused by System.Drawing usage or ambiguous Font references.
    • Preferred fix: Use Aspose.Drawing only and prefer explicit Aspose.Drawing type names when ambiguity is possible.

Build and run contract

  • Target framework: net8.0
  • Package: Aspose.Words 26.9.0
  • Package: Aspose.Drawing.Common 26.8.0
  • Package: Newtonsoft.Json

Command reference

Create a temporary console project

dotnet new console -n ExampleProject --framework net8.0
cd ExampleProject

Add required packages

dotnet add package Aspose.Words --version 26.9.0
dotnet add package Aspose.Drawing.Common --version 26.8.0
dotnet add package Newtonsoft.Json

Copy a category example into the temp project

Copy-Item ..\find-and-replace\<example-file>.cs .\Program.cs

Build and run

dotnet build --configuration Release --verbosity minimal
dotnet run --configuration Release --no-build

Category update guidance

  • Preserve file-to-task traceability. Any future update should keep the original task text associated with the file in metadata.
  • When replacing a file, prefer the latest verified publish-ready version rather than a merely compiling draft.
  • Keep examples standalone, bootstrap missing inputs locally, and prefer documented Aspose APIs over speculative shortcuts.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.