Created
November 7, 2020 07:42
-
-
Save Zylvian/47ecd6d1953b8d8c3900dc30645efe98 to your computer and use it in GitHub Desktop.
Word replacer for Word Document (C#)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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