TextRange Class
Represents a contiguous area in a presentation between two TextPositions.
- Inheritance:
- System.ObjectTextRange
Remarks
TextRange is defined by a starting and ending TextPosition.
TextRange instances are used to identify specific portions of a presentation. TextRange instance only exists while the programming code that defined it is running.
TextPosition enables to view the presentation as a contiguous sequence of characters by hiding the complexity of the underlying hierarchical content model.
TextRange offers following functionalities:
- Delete part of the presentation content with Delete() method.
- Set new content to a part of the presentation content with LoadText(String) method.
- Insert new content before or after a part of the presentation content with Start.LoadText(String) and End.LoadText(String) methods.
- Find all parts of the presentation content which match the specified string or specified System.Text.RegularExpressions.Regex with Find(String) methods.
- Export part of the presentation content to a textual format with ToString() method.
For more information, see Find and Replace example.
Constructors
TextRange(TextPosition, TextPosition)
Initializes a new instance of the TextRange class.
public TextRange(TextPosition start, TextPosition end)
Public Sub New(start As TextPosition, end As TextPosition)
Parameters
start
- TextPosition
The TextPosition that marks the beginning of the new TextRange.
end
- TextPosition
The TextPosition that marks the end of the new TextRange.
Exceptions
- System.ArgumentNullException
Argument start
or end
is null.
Properties
End
Gets the TextPosition that marks the end of the current TextRange.
Property Value
The TextPosition that marks the end of the current TextRange.
LoadTextFormat
Gets the character formatting options for text loaded with LoadText(String) method or null if text cannot be loaded to the current TextRange.
public TextCharacterFormat LoadTextFormat { get; }
Public ReadOnly Property LoadTextFormat As TextCharacterFormat
Property Value
The character formatting options for text loaded with LoadText(String) method or null if text cannot be loaded to the current TextRange.
Remarks
It is necessary to use this property on the same instance that will be used for loading text. Accessing the TextContent property of an element, such as TextContent, always creates a new instance. Therefore the value returned from the property needs to be stored in a variable and used both for setting the text format as well as loading the text.
Start
Gets the TextPosition that marks the beginning of the current TextRange.
Property Value
The TextPosition that marks the beginning of the current TextRange.
Methods
Delete()
Deletes the presentation content specified with the current TextRange.
Find(String)
Finds all TextRanges which contain the specified text.
public IEnumerable<TextRange> Find(string text)
Public Function Find(text As String) As IEnumerable(Of TextRange)
Parameters
text
- System.String
The text which should be searched for.
Returns
Remarks
For more information, see Find and Replace example.
Exceptions
- System.ArgumentException
Argument text can't be null or empty.
Find(Regex)
Finds all TextRanges which match the specified System.Text.RegularExpressions.Regex.
public IEnumerable<TextRange> Find(Regex regex)
Public Function Find(regex As Regex) As IEnumerable(Of TextRange)
Parameters
regex
- System.Text.RegularExpressions.Regex
The System.Text.RegularExpressions.Regex which should be matched.
Returns
- System.Collections.Generic.IEnumerable<TextRange>
All TextRanges which match the specified System.Text.RegularExpressions.Regex.
Remarks
For more information, see Find and Replace example.
LoadText(String)
Loads the specified text
to the current TextRange.
Parameters
text
- System.String
The text which should be loaded to the current TextRange.
Returns
Remarks
A load operation replaces the current TextRange's content with the newly loaded content.
LoadText(String, HtmlLoadOptions)
Loads the specified (interpreted) htmlText
to the current TextRange.
public TextRange LoadText(string htmlText, HtmlLoadOptions options)
Public Function LoadText(htmlText As String, options As HtmlLoadOptions) As TextRange
Parameters
htmlText
- System.String
The HTML text which should be loaded to the current TextRange.
options
- HtmlLoadOptions
The options used to define settings for load operation.
Returns
Remarks
A load operation replaces the current TextRange's content with the newly loaded content.
Replace(String, String)
Replaces all occurrences of the specified text with another text in the current TextRange.
public void Replace(string oldValue, string newValue)
Public Sub Replace(oldValue As String, newValue As String)
Parameters
oldValue
- System.String
The text which should be searched for.
newValue
- System.String
The text which should replace all occurrences of searched text.
Remarks
For more information, see Find and Replace example.
Replace(Regex, String)
Replaces all matches of the specified System.Text.RegularExpressions.Regex with specified text in the current TextRange.
public void Replace(Regex regex, string replacement)
Public Sub Replace(regex As Regex, replacement As String)
Parameters
regex
- System.Text.RegularExpressions.Regex
The Regex which should be matched.
replacement
- System.String
The text which should replace all matches of searched System.Text.RegularExpressions.Regex.
Remarks
For more information, see Find and Replace example.
ToString()
Returns a plain text that represents this TextRange instance.
Returns
- System.String
A plain text that represents this TextRange instance.