Skip to content

Instantly share code, notes, and snippets.

@Zylvian
Created November 7, 2020 07:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zylvian/47ecd6d1953b8d8c3900dc30645efe98 to your computer and use it in GitHub Desktop.
Save Zylvian/47ecd6d1953b8d8c3900dc30645efe98 to your computer and use it in GitHub Desktop.
Word replacer for Word Document (C#)
using System;
using System.Text.RegularExpressions;
namespace ConsoleApp1
{
class Doc_Replacer
{
static void Main(string[] args)
{
// Import word document and convert into string.
string wordDoc =
@"We like working here at Leadsoft IT.
We are not limited here at Leadsoft It Limited.";
Replacer(wordDoc);
}
static string Replacer(string wordDoc)
{
string replaceWith = "Leadsoft IT Limited";
string pattern = "(Leadsoft IT(?!.*Limited))";
string print_str = Regex.Replace(wordDoc, pattern, replaceWith
, RegexOptions.IgnoreCase);
// Console.WriteLine(print_str);
return print_str;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment