Find Method
- Namespace
TXTextControl
- Package
TXTextControl.asTextControl. Core. SDK TXTextControl.from the private NuGet feed or Text Control Offline PackagesCore. dll
- Also in
TXTextControl.asTextControl. ASP. SDK TXTextControl.dll
Description
Finds a text string in a text frame.
Syntax
public int Find(string text, int start, FindOptions options);Public Function Find(text As String, start As Integer, options As FindOptions) As IntegerParameters
| Parameter | Description |
|---|---|
| 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++);
}Dim position As Integer = 0, count As Integer = 0
For Each tf As TextFrame In textControl1.TextFrames
position = 0
While (position = tf.Find("test", position, FindOptions.NoHighlight Or FindOptions.NoMessageBox)) <> -1
count += 1
position += 1
End While
NextThe 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}.");
}Dim formattedSelection As Selection = textFrame.Selection
formattedSelection.Bold = True
textFrame.Selection = formattedSelection
Dim position As Integer = textFrame.Find("Quarterly results", 1, FindOptions.Reverse)
If position >= 0 Then
Console.WriteLine($"Found at position {position}.")
End If