Deutsch Indonesia Tiếng Việt فارسی English Italiano Türkçe ไทย Español Polski Русский 日本語 Français Português العربية

Replace Text in DOC with C#

Wordize for .NET is an efficient solution for text replacement in DOC documents. The Replacer class enables C# developers to programmatically replace text fragments in DOC using both simple strings and regular expressions.

Key Features:
  • Simple find and replace text - the Replacer.Replace() method performs text replacement throughout all parts of DOC documents while preserving formatting
  • Regex support for complex text transformations, including text replacement using capture groups
  • Flexible search options - the FindReplaceOptions class controls search parameters, including case sensitivity, whole word matching, ignoring text in various document elements, and more
  • Substitutions in replacement text - use UseSubstitutions for special replacement patterns: found text, text before match, text after match
  • Formatted replacement - support for specialized markup in replacement text through ReplacementFormat
  • Export results to image format - the ReplaceToImages() method returns results as an array of images
  • Fluent API support for find and replace text operations through ReplacerContext and method chaining, adding clarity to your C# code
Use Cases:
  • Standardize DOC document styling
  • Validate information in DOC documents
  • Replace placeholder fields with actual data
  • Remove or mask personal data

Test the capabilities of programmatic DOC text replacement in the interactive online demo presented on this page. Simply upload your DOC document, specify the search text and replacement text, run the operation, and download the updated file for verification. The provided C# code snippet is ready for use in your .NET project.

C#
Run code
Upload your document
Select output format from the list
using Wordize.Replacing;

Replacer.Replace("Input.doc", "Output.doc", "Text or Regex", "Text or Regex");
using Wordize.Replacing; Replacer.Replace("Input.doc", "Output.doc", "Text or Regex", "Text or Regex"); using Wordize.Replacing; using Wordize.Saving; var imageStreams = Replacer.ReplaceToImages("Input.doc", new ImageSaveOptions(SaveFormat.Doc), "Text or Regex", "Text or Regex"); foreach (var (stream, page) in imageStreams.Select((s, i) => (s, i))) { using var _ = stream; stream.Position = 0; using var file = File.Create($"Output_{page + 1}.doc"); stream.CopyTo(file); }
using Wordize.Replacing;

FindReplaceOptions options = new FindReplaceOptions() { UseSubstitutions = true };
Replacer.Replace("Input.doc", "Output.doc", new Regex(@"Text or Regex"), "Text or Regex", options);
using Wordize.Replacing; FindReplaceOptions options = new FindReplaceOptions() { UseSubstitutions = true }; Replacer.Replace("Input.doc", "Output.doc", new Regex(@"Text or Regex"), "Text or Regex", options); using Wordize.Replacing; using Wordize.Saving; FindReplaceOptions options = new FindReplaceOptions() { UseSubstitutions = true }; var imageStreams = Replacer.ReplaceToImages("Input.doc", new ImageSaveOptions(SaveFormat.Doc), new Regex(@"Text or Regex"), "Text or Regex", options); foreach (var (stream, page) in imageStreams.Select((s, i) => (s, i))) { using var _ = stream; stream.Position = 0; using var file = File.Create($"Output_{page + 1}.doc"); stream.CopyTo(file); }
Run code

How to Replace Text in DOC with C#

  1. Add Wordize SDK to your .NET project
  2. Call the Replacer.Replace() method, specifying the DOC document, search text, replacement text, and search parameters
  3. Get the DOC document with replaced text
5%