You are here: Plugin API > Samples > How To Search And Change Style Of Text

.

How to Search and Change Style of Text

Below is a basic example of using the IEditorContext to search for a input string and change the style of it throughout the document. Assume your class instance of IEditorContext is named "mEditorContext."

private void SearchAndChangeStyle(string searchString)

{

IDocument currentDocument = mEditorContext.GetActiveDocument();

if (currentDocument != null)

{

string text = currentDocument.GetDocumentText();

int occurences = Regex.Matches(text, searchString).Count;

for (int i = 0; i < occurences; i++)

{

currentDocument.Select(searchString);

currentDocument.Selection.ChangeBackColor(Color.Yellow);

currentDocument.Selection.ChangeForeColor(Color.Red);

currentDocument.Selection.ChangeFontFamily("Comic Sans MS");

}

}

}