TX Text Control .NET for WPF

Find Method

Method|Introduced in 12.0
Namespace
TXTextControl
Package
TXTextControl.TextControl.WPF.SDK as TXTextControl.Server.dll from the private NuGet feed or Text Control Offline Packages

Description

Finds a text string in the main text of the document.

Syntax

Find(string)

Finds the specified text string in the main text of the document. The search starts at the beginning of the document.

public int Find(string text);
ParameterDescription
text

Specifies the text to search for.

Find(string, int, FindOptions)

Finds the specified text string in the main text of the document using the specified find options. The search starts at the specified position.

public int Find(string text, int start, FindOptions options);
ParameterDescription
text

Specifies the text to search for.

start

Specifies the text position where the search starts, beginning with 0. If this value is -1, the search begins at the current text input position.

options

Specifies search options. It can be a combination of the FindOptions values.

Return Value

If the text searched for is found, the method returns the index (zero-based) of the first character of the search string. If the specified text is not found the method returns -1.

Examples

The following example finds a revenue label, selects it, and applies bold formatting.

textControl.Text = "Revenue: $125,000";
int position = textControl.Find("Revenue");

if (position >= 0)
{
    textControl.Select(position, "Revenue".Length);
    textControl.Selection.Bold = true;
}