DOM.Elements.TextElements.TextContainer
Represents a container capable of holding multiple text runs. Amanages the lifecycle ofelements, provides text-creation helpers, and supports search, replace, and removal operations across all contained text elements.
8 members
Properties
Gets a collection of allelements contained within this container. This property dynamically filters child elements and returns only text nodes.
Methods
AddText
2 overloadsIText AddText(string text)Creates a newelement using the provided string content and adds it to the container.
Parameters
- text
- The textual content to wrap inside a newelement.
Returns
IText
The newly createdinstance.
AddText(IText text)Adds an existingelement to the container.
Parameters
- text
- The text element to add.
Returns
The sameinstance to enable fluent usage.
Find
IText Find(string searchText, RegexOptions? regexOption, bool wholeWordOnly, bool caseSensitive)Searches all containedelements for the specified text. Applies optional regular expression behavior, whole-word matching, and case-sensitivity. Returns the indices of the text elements that contain at least one match.
Parameters
- searchText
- The text to search for. Cannot be null.
- regexOption
- Optional to apply.
- wholeWordOnly
- Whether the match must correspond to a whole-word boundary.
- caseSensitive
- Whether the search is case-sensitive.
Returns
IText
A list of indices corresponding toelements that contain a match.
Exceptions
- System.ArgumentNullException: Thrown whenis null.
RemoveText
3 overloadsRemoveText(int index)Removes a text element at the specified index, if it exists within this container.
Parameters
- index
- The index of the text element to remove.
RemoveText(IText text)Removes the specifiedelement from this container.
Parameters
- text
- The text element to remove.
RemoveText(string text)Removes all occurrences of the specified literal text by replacing it with an empty string. Removal is performed case-insensitively.
Parameters
- text
- The text to remove.
Replace
TextContainer Replace(string searchText, string replaceText, RegexOptions? regexOption, bool wholeWordOnly, bool caseSensitive)Replaces occurrences of the specified text across all containedelements. Applies optional regular expression behavior, whole-word matching, and case-sensitivity.
Parameters
- searchText
- The text to search for.
- replaceText
- The replacement text.
- regexOption
- Optional to apply.
- wholeWordOnly
- Whether to restrict matches to whole words.
- caseSensitive
- Whether the operation should be case-sensitive.