Range Class

Represents a contiguous area in a document.

ExpandedInheritance Hierarchy

SystemObject
  Aspose.WordsRange

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.9.0

ExpandedSyntax

public class Range

The Range type exposes the following members.

ExpandedProperties

  NameDescription
Public propertyCode exampleBookmarks
Returns a Bookmarks collection that represents all bookmarks in the range.
Public propertyFields
Returns a Fields collection that represents all fields in the range.
Public propertyCode exampleFormFields
Returns a FormFields collection that represents all form fields in the range.
Public propertyCode exampleText
Gets the text of the range.

ExpandedMethods

  NameDescription
Public methodCode exampleDelete
Deletes all characters of the range.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodNormalizeFieldTypes
Changes field type values FieldType of FieldStart, FieldSeparator, FieldEnd in this range so that they correspond to the field types contained in the field codes.
Public methodCode exampleReplace(String, String)
Replaces all occurrences of a specified character string pattern with a replacement string.
Public methodCode exampleReplace(Regex, String)
Replaces all occurrences of a character pattern specified by a regular expression with another string.
Public methodCode exampleReplace(String, String, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string.
Public methodCode exampleReplace(Regex, String, FindReplaceOptions)
Replaces all occurrences of a character pattern specified by a regular expression with another string.
Public methodToDocument
Constructs a new fully formed document that contains the range.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodCode exampleUnlinkFields
Unlinks fields in this range.
Public methodCode exampleUpdateFields
Updates the values of document fields in this range.

ExpandedRemarks

The document is represented by a tree of nodes and the nodes provide operations to work with the tree, but some operations are easier to perform if the document is treated as a contiguous sequence of text.

Range is a "facade" interface that provide methods that treat the document or portions of the document as "flat" text regardless of the fact that the document nodes are stored in a tree-like object model.

Range does not contain any text or nodes, it is merely a view or "window" over a fragment of a document.

ExpandedExamples

Shows how to get the text contents of all the nodes that a range covers.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Hello world!");

Assert.AreEqual("Hello world!", doc.Range.Text.Trim());

ExpandedSee Also