Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created January 29, 2021 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/39da615415fd5187cfd70d308e0dba17 to your computer and use it in GitHub Desktop.
Save bjoerntx/39da615415fd5187cfd70d308e0dba17 to your computer and use it in GitHub Desktop.
// load a document
textControl1.Load("sample.html", TXTextControl.StreamType.HTMLFormat);
// create a MatchCollection
MatchCollection matchedFields = textControl1.Find(@"#(.*)#", RegexOptions.None);
// loop through all matches
foreach (Match match in matchedFields) {
// select the text
textControl1.Select(match.Index, match.Length);
// create a new field based on the text
TXTextControl.DocumentServer.Fields.MergeField mergeField =
new TXTextControl.DocumentServer.Fields.MergeField() {
Text = textControl1.Selection.Text,
Name = textControl1.Selection.Text.Trim('#')
};
// enable highlighting and the second input position
mergeField.ApplicationField.DoubledInputPosition = true;
mergeField.ApplicationField.HighlightMode = TXTextControl.HighlightMode.Activated;
// remove the text
textControl1.Selection.Text = "";
// insert the field at the current input position
textControl1.ApplicationFields.Add(mergeField.ApplicationField);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment