Skip to content

FormattedText.Find

Public Class

Returns a text range identifying the first occurrence of the given string within the text, starting from a given index.

Namespace: Autodesk.Revit.DB

Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)

Syntax

public TextRange Find(
string searchString,
int startIndex,
bool matchCase,
bool matchWholeWord
)

Parameters

searchStringString

The text to search for.

startIndexInt32

The start index to search within the text.

matchCaseBoolean

True if the case must match when searching the formatted text, false to search in a case-insensitive manner.

matchWholeWordBoolean

True if the match must be a whole word when searching the formatted text, false otherwise.

Return Value

TextRange
The text range identified.

Exceptions

Exception

Condition


ArgumentException

searchString is an empty string. -or- searchString contains invalid characters such as a newline character.


ArgumentNullException

A non-optional argument was null


ArgumentOutOfRangeException

The given value for startIndex is negative.


Remarks

Returns an empty text range:

  • if the given string cannot be found in the text.
  • if the given start index is beyond the length of the entire text.

The search can be case-sensitive or case-insensitive. The search can be set to match whole words or part of words.

Example

#region Autodesk.Revit.DB.FormattedText.#ctor(System.String)
public void ReformatText(TextNote textNote, string textToChange)
{
String plainText = textNote.Text;
FormattedText formattedText = new FormattedText(plainText);
TextRange foundRange = formattedText.Find(textToChange, 0, false, true);
while (foundRange.Length > 0)
{
formattedText.SetBoldStatus(foundRange, true);
foundRange = formattedText.Find(textToChange, foundRange.End, false, true);
}
textNote.SetFormattedText(formattedText);
}
#endregion