I have issues with blank space as well. I did try to set up as you had described earlier. And tried using \b switch too. Can you show again what I am doing wrong and also the requirement is to have . if middlename exist. Issue is if its null its still inserting blank space. I have tried \b as well if its null.
Regex regex = new Regex(" ");
FindReplaceOptions options = new FindReplaceOptions();
options.IgnoreFields = true;
// Replace 'e' in document while ignoring deleted text.
options.IgnoreDeleted = true;
// doc.Range.Replace(regex, "", options);
doc.UpdateFields();
doc.Range.Replace(new Regex(@" <MiddleInitial>"), string.Empty, options);
doc.Range.Replace(new Regex(@" <PartyMiddleName>"), string.Empty, options);
doc.Range.Replace(new Regex(@" <MiddleName>"), string.Empty, options);
doc.Range.Replace(new Regex(@" <Vasrd>,"), string.Empty, options);
doc.Range.Replace(new Regex(@" <crsceffdates>,"), string.Empty, options);
doc.Range.Replace(new Regex(@" <Vasrd1>,"), string.Empty, options);
doc.Range.Replace(new Regex(@" <Vasrd2>,"), string.Empty, options);
doc.Range.Replace(new Regex(@" <Vasrd3>,"), string.Empty, options);
doc.Range.Replace(new Regex(@" <LatestDisabilityPercentage>,"), string.Empty, options);
doc.Range.Replace(new Regex(@" <VADiagnosticDesc>,"), string.Empty, options);
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyTableRows | MailMergeCleanupOptions.RemoveUnusedFields | MailMergeCleanupOptions.RemoveEmptyParagraphs | MailMergeCleanupOptions.RemoveContainingFields;
doc.MailMerge.DeleteFields();
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.UnusedBuiltinStyles = true;
doc.Cleanup(cleanupOptions);
if (DT.Rows[0]["PartyMiddleName"].ToString() != "")
{
DT.Rows[0]["MiddleInitial"] = ' ' + Util.FormatTextToUpper(DT.Rows[0]["PartyMiddleName"].ToString().Substring(0, 1) + ".");
}
else
{
DT.Rows[0]["MiddleInitial"] = "\b";
}
A CH61 APPROVAL (KL) (5).docx (88.5 KB)