Aspose::Words::Range Class Reference

Represents a contiguous area in a document. More...

#include "Model/Text/Range.h"

Inherits System::Object.

Public Member Functions

System::String get_Text ()
 Gets the text of the range. More...
 
System::SharedPtr< Aspose::Words::Fields::FormFieldCollectionget_FormFields ()
 Returns a Aspose::Words::Range::get_FormFields collection that represents all form fields in the range. More...
 
System::SharedPtr< Aspose::Words::BookmarkCollectionget_Bookmarks ()
 Returns a Aspose::Words::Range::get_Bookmarks collection that represents all bookmarks in the range. More...
 
System::SharedPtr< Aspose::Words::Fields::FieldCollectionget_Fields ()
 Returns a Aspose::Words::Range::get_Fields collection that represents all fields in the range. More...
 
void Delete ()
 Deletes all characters of the range. More...
 
int32_t Replace (System::String pattern, System::String replacement)
 Replaces all occurrences of a character pattern specified by a regular expression with another string. More...
 
int32_t Replace (System::SharedPtr< System::Text::RegularExpressions::Regex > pattern, System::String replacement)
 Replaces all occurrences of a character pattern specified by a regular expression with another string. More...
 
int32_t Replace (System::String pattern, System::String replacement, System::SharedPtr< Aspose::Words::Replacing::FindReplaceOptions > options)
 Replaces all occurrences of a character pattern specified by a regular expression with another string. More...
 
int32_t Replace (System::SharedPtr< System::Text::RegularExpressions::Regex > pattern, System::String replacement, System::SharedPtr< Aspose::Words::Replacing::FindReplaceOptions > options)
 Replaces all occurrences of a character pattern specified by a regular expression with another string. More...
 
void UpdateFields ()
 Updates the values of document fields in this range. More...
 
void UnlinkFields ()
 Unlinks fields in this range. More...
 
void NormalizeFieldTypes ()
 Changes field type values Aspose::Words::Fields::FieldChar::get_FieldType of Aspose::Words::Fields::FieldStart, Aspose::Words::Fields::FieldSeparator, Aspose::Words::Fields::FieldEnd in this range so that they correspond to the field types contained in the field codes. More...
 
System::SharedPtr< Aspose::Words::DocumentToDocument ()
 Constructs a new fully formed document that contains the range. More...
 
- Public Member Functions inherited from System::Object
 Object ()
 Creates object. Initializes all internal data structures. More...
 
virtual ~Object ()
 Destroys object. Frees all internal data structures. More...
 
 Object (Object const &x)
 Copy constructor. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
Objectoperator= (Object const &x)
 Assignment operator. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
ObjectSharedRefAdded ()
 Increments shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int SharedRefRemovedSafe ()
 Decrements and returns shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int RemovedSharedRefs (int count)
 Decreases shared reference count by specified value. More...
 
Detail::SmartPtrCounter * WeakRefAdded ()
 Increments weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
void WeakRefRemoved ()
 Decrements weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
Detail::SmartPtrCounter * GetCounter ()
 Gets reference counter data structure associated with the object. More...
 
int SharedCount () const
 Gets current value of shared refernce counter. More...
 
void Lock ()
 Implements C# lock() statement locking. Call directly or use LockContext sentry object. More...
 
void Unlock ()
 Implements C# lock() statement unlocking. Call directly or use LockContext sentry object. More...
 
virtual bool Equals (ptr obj)
 Compares objects using C# Object.Equals semantics. More...
 
virtual int GetHashCode () const
 Analog of C# Object.GetHashCode() method. Enables hashing of custom objects. More...
 
virtual String ToString () ASPOSE_CONST
 Analog of C# Object.ToString() method. Enables converting custom objects to string. More...
 
virtual ptr MemberwiseClone () const
 Analog of C# Object.MemberwiseClone() method. Enables cloning custom types. More...
 
virtual const TypeInfoGetType () const
 Gets actual type of object. Analog of C# System.Object.GetType() call. More...
 
virtual bool Is (const TypeInfo &targetType) const
 Check if object represents an instance of type described by targetType. Analog of C# 'is' operator. More...
 
virtual void SetTemplateWeakPtr (unsigned int argument)
 Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containers to weak mode. More...
 

Additional Inherited Members

- Public Types inherited from System::Object
typedef SmartPtr< Objectptr
 Alias for smart pointer type. More...
 
typedef System::Details::SharedMembersType shared_members_type
 structure to keep list of shared pointers contained in object. More...
 
- Static Public Member Functions inherited from System::Object
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 Reference-compares value type object with nullptr. More...
 
template<typename T1 , typename T2 >
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares reference type objects in C# style. More...
 
template<typename T1 , typename T2 >
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares value type objects in C# style. More...
 
static const TypeInfoType ()
 Impleemnts C# typeof(System.Object) construct. More...
 
template<>
bool Equals (float const &objA, float const &objB)
 
template<>
bool Equals (double const &objA, double const &objB)
 
template<>
bool ReferenceEquals (String const &str, std::nullptr_t)
 
template<>
bool ReferenceEquals (String const &str1, String const &str2)
 

Detailed Description

Represents a contiguous area in a document.

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.

Member Function Documentation

◆ Delete()

void Aspose::Words::Range::Delete ( )

Deletes all characters of the range.

◆ get_Bookmarks()

System::SharedPtr<Aspose::Words::BookmarkCollection> Aspose::Words::Range::get_Bookmarks ( )

Returns a Aspose::Words::Range::get_Bookmarks collection that represents all bookmarks in the range.

◆ get_Fields()

System::SharedPtr<Aspose::Words::Fields::FieldCollection> Aspose::Words::Range::get_Fields ( )

Returns a Aspose::Words::Range::get_Fields collection that represents all fields in the range.

◆ get_FormFields()

System::SharedPtr<Aspose::Words::Fields::FormFieldCollection> Aspose::Words::Range::get_FormFields ( )

Returns a Aspose::Words::Range::get_FormFields collection that represents all form fields in the range.

◆ get_Text()

System::String Aspose::Words::Range::get_Text ( )

Gets the text of the range.

The returned string includes all control and special characters as described in Aspose::Words::ControlChar.

◆ NormalizeFieldTypes()

void Aspose::Words::Range::NormalizeFieldTypes ( )

Changes field type values Aspose::Words::Fields::FieldChar::get_FieldType of Aspose::Words::Fields::FieldStart, Aspose::Words::Fields::FieldSeparator, Aspose::Words::Fields::FieldEnd in this range so that they correspond to the field types contained in the field codes.

Use this method after document changes that affect field types.

To change field type values in the whole document use Aspose::Words::Document::NormalizeFieldTypes.

◆ Replace() [1/4]

int32_t Aspose::Words::Range::Replace ( System::SharedPtr< System::Text::RegularExpressions::Regex pattern,
System::String  replacement 
)

Replaces all occurrences of a character pattern specified by a regular expression with another string.

Replaces the whole match captured by the regular expression.

Method is able to process breaks in both pattern and replacement strings.

You should use special meta-characters if you need to work with breaks:

  • &p - paragraph break
  • &b - section break
  • &m - page break
  • &l - manual line break

Use method Aspose::Words::Range::Replace(System::SharedPtr<$System::Text::RegularExpressions::Regex>, System::String, System::SharedPtr<Aspose::Words::Replacing::FindReplaceOptions>) to have more flexible customization.

Parameters
patternA regular expression pattern used to find matches.
replacementA string to replace all occurrences of pattern.
Returns
The number of replacements made.

◆ Replace() [2/4]

int32_t Aspose::Words::Range::Replace ( System::SharedPtr< System::Text::RegularExpressions::Regex pattern,
System::String  replacement,
System::SharedPtr< Aspose::Words::Replacing::FindReplaceOptions options 
)

Replaces all occurrences of a character pattern specified by a regular expression with another string.

Replaces the whole match captured by the regular expression.

Method is able to process breaks in both pattern and replacement strings.

You should use special meta-characters if you need to work with breaks:

  • &p - paragraph break
  • &b - section break
  • &m - page break
  • &l - manual line break

To leave any meta-character intact a parameter Aspose::Words::Replacing::FindReplaceOptions::get_PreserveMetaCharacters should be set to true.

Parameters
patternA regular expression pattern used to find matches.
replacementA string to replace all occurrences of pattern.
optionsAspose::Words::Replacing::FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.

◆ Replace() [3/4]

int32_t Aspose::Words::Range::Replace ( System::String  pattern,
System::String  replacement 
)

Replaces all occurrences of a character pattern specified by a regular expression with another string.

Used case-insensitive comparison.

Replaces the whole match captured by the regular expression.

Method is able to process breaks in both pattern and replacement strings.

You should use special meta-characters if you need to work with breaks:

  • &p - paragraph break
  • &b - section break
  • &m - page break
  • &l - manual line break

Use method Aspose::Words::Range::Replace(System::String, System::String, System::SharedPtr<Aspose::Words::Replacing::FindReplaceOptions>) to have more flexible customization.

Parameters
patternA string to be replaced.
replacementA string to replace all occurrences of pattern.
Returns
The number of replacements made.

◆ Replace() [4/4]

int32_t Aspose::Words::Range::Replace ( System::String  pattern,
System::String  replacement,
System::SharedPtr< Aspose::Words::Replacing::FindReplaceOptions options 
)

Replaces all occurrences of a character pattern specified by a regular expression with another string.

Replaces the whole match captured by the regular expression.

Method is able to process breaks in both pattern and replacement strings.

You should use special meta-characters if you need to work with breaks:

  • &p - paragraph break
  • &b - section break
  • &m - page break
  • &l - manual line break

To leave any meta-character intact a parameter Aspose::Words::Replacing::FindReplaceOptions::get_PreserveMetaCharacters should be set to true.

Parameters
patternA string to be replaced.
replacementA string to replace all occurrences of pattern.
optionsAspose::Words::Replacing::FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.

◆ ToDocument()

System::SharedPtr<Aspose::Words::Document> Aspose::Words::Range::ToDocument ( )

Constructs a new fully formed document that contains the range.

◆ UnlinkFields()

void Aspose::Words::Range::UnlinkFields ( )

Unlinks fields in this range.

Replaces all the fields in this range with their most recent results.

To unlink fields in the whole document use Aspose::Words::Range::UnlinkFields.

◆ UpdateFields()

void Aspose::Words::Range::UpdateFields ( )

Updates the values of document fields in this range.

When you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call this method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document.

There is no need to update fields after executing a mail merge because mail merge is a kind of field update and automatically updates all fields in the document.

This method does not update all field types. For the detailed list of supported field types, see the Programmers Guide.

This method does not update fields that are related to the page layout algorithms (e.g. PAGE, PAGES, PAGEREF). The page layout-related fields are updated when you render a document or call Aspose::Words::Document::UpdatePageLayout.

To update fields in the whole document use Aspose::Words::Document::UpdateFields.