TX Text Control .NET for WPF

Find Method

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

Description

Finds a text string in a text frame.

Syntax

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

Parameters

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 counts all occurrences of the specified string in all text frames of a TX Text Control document:

int position = 0, count = 0;

foreach (TextFrame tf in textControl1.TextFrames)
{
    for (position=0;
    (position = tf.Find("test", position, FindOptions.NoHighlight | FindOptions.NoMessageBox)) != -1;
    count++, position++);
}

The following example applies bold formatting through the text frame's selection by using TextFrame.Find.

Selection formattedSelection = textFrame.Selection;
formattedSelection.Bold = true;
textFrame.Selection = formattedSelection;

int position = textFrame.Find("Quarterly results", 1, FindOptions.Reverse);
if (position >= 0)
{
    Console.WriteLine($"Found at position {position}.");
}