Created
January 29, 2021 22:10
-
-
Save bjoerntx/39da615415fd5187cfd70d308e0dba17 to your computer and use it in GitHub Desktop.
This file contains 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
// 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