Click or drag to resize
TextRangeFindText Method (String, Int32, RangeMatchType)
Searches up to count characters for the text given by text. The starting position and direction are also specified by count, and the matching criteria are given by flags.

Namespace: TextObjectModel
Assembly: ManagedTOM2 (in ManagedTOM2.dll) Version: 1.0.5577.41188
Syntax
public int FindText(
	string text,
	int count,
	[OptionalAttribute] RangeMatchType flags
)

Parameters

text
Type: SystemString
String to find.
count
Type: SystemInt32
Maximum number of characters to search.
flags (Optional)
Type: TextObjectModelRangeMatchType
Flags governing comparisons.

Return Value

Type: Int32
The length of string matched.
Examples
The following example demonstrates how to find text in a range:
C#
void FindTextExample(TextDocument document) {
    TextRange range = document.EntireRange;
    range.Text = "This is my first. This is my second.";

    int result;

    result = range.FindText("my");

    // substring found at position 8
    if (result > 0)
        Console.WriteLine("Substring found at position {0}", range.Start);
    else
        Console.WriteLine("Substring not found");

    range.Expand(TextUnit.Story);
    result = range.FindText("my", 6);

    // substring not found
    if (result > 0)
        Console.WriteLine("Substring found at position {0}", range.Start);
    else
        Console.WriteLine("Substring not found");
}
See Also