GemBox.Presentation
  • Overview
  • Examples
  • Free version
  • Support
  • Pricelist

    Show / Hide Table of Contents

    TextRange Class

    Namespace:
    GemBox.Presentation
    Assembly:
    GemBox.Presentation.dll

    Represents a contiguous area in a presentation between two TextPositions.

    • C#
    • VB.NET
    public class TextRange
    Public Class TextRange
    Inheritance:
    System.Object
    TextRange
    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.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    public TextPosition End { get; }
    Public ReadOnly Property End As TextPosition
    Property Value
    TextPosition

    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.

    • C#
    • VB.NET
    public TextCharacterFormat LoadTextFormat { get; }
    Public ReadOnly Property LoadTextFormat As TextCharacterFormat
    Property Value
    TextCharacterFormat

    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.

    • C#
    • VB.NET
    public TextPosition Start { get; }
    Public ReadOnly Property Start As TextPosition
    Property Value
    TextPosition

    The TextPosition that marks the beginning of the current TextRange.

    Methods

    Delete()

    Deletes the presentation content specified with the current TextRange.

    • C#
    • VB.NET
    public void Delete()
    Public Sub Delete

    Find(String)

    Finds all TextRanges which contain the specified text.

    • C#
    • VB.NET
    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
    System.Collections.Generic.IEnumerable<TextRange>

    All TextRanges which contain the specified text.

    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.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    public TextRange LoadText(string text)
    Public Function LoadText(text As String) As TextRange
    Parameters
    text
    System.String

    The text which should be loaded to the current TextRange.

    Returns
    TextRange

    A TextRange instance which contains loaded text.

    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.

    • C#
    • VB.NET
    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
    TextRange

    A TextRange instance which contains loaded text.

    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.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    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.

    • C#
    • VB.NET
    public override string ToString()
    Public Overrides Function ToString As String
    Returns
    System.String

    A plain text that represents this TextRange instance.

    Overrides
    System.Object.ToString()

    Examples

    Find and Replace example
    Back to top

    Facebook • Twitter • LinkedIn

    © GemBox Ltd. — All rights reserved.