This is a great tool.
I'm trying to find a solution where I can parse the following text and replace with a new one.
old:
Dated this 03 day of September, 2014
new:
Dated this 22 day of October, 2014
How can I achieve this functionality?
Thank you!!!
Document doc = new Document();
doc.LoadFromFile("Test.docx", FileFormat.Docx2010);
doc.Replace("Dated this 03 day of September, 2014", "Dated this 22 day of October, 2014", true, true);
doc.SaveToFile("Result.docx", FileFormat.Docx2010);
Document doc = new Document();
doc.LoadFromFile("Test.docx", FileFormat.Docx2010);
string pattern = @"Dated.*";
Regex regex = new Regex(pattern);
TextSelection[] selections = doc.FindAllPattern(regex);
string time = DateTime.Now.ToString("yyyy-MMMM-dd", CultureInfo.CreateSpecificCulture("en-US"));
string[] timeString = time.Split('-');
for (int i = 0; i < selections.Count(); i++)
{
string temp = string.Format("Dated this {0} day of {1}, {2}", timeString[2], timeString[1], timeString[0]);
doc.Replace(selections[i].SelectedText, temp, true, true);
}
doc.SaveToFile("Result.docx", FileFormat.Docx2010);