FindReplaceOptionsUseSubstitutions Property

Gets or sets a boolean value indicating whether to recognize and use substitutions within replacement patterns. The default value is false.

Namespace:  Aspose.Words.Replacing
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.11.0

ExpandedSyntax

public bool UseSubstitutions { get; set; }

Property Value

Type: Boolean

ExpandedRemarks

For the details on substitution elements please refer to: https://docs.microsoft.com/en-us/dotnet/standard/base-types/substitutions-in-regular-expressions.

ExpandedExamples

Shows how to recognize and use substitutions within replacement patterns.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Write some text
builder.Write("Jason give money to Paul.");

Regex regex = new Regex(@"([A-z]+) give money to ([A-z]+)");

// Replace text using substitutions
FindReplaceOptions options = new FindReplaceOptions();
options.UseSubstitutions = true;
doc.Range.Replace(regex, @"$2 take money from $1", options);

Assert.AreEqual(doc.GetText(), "Paul take money from Jason.\f");
Shows how to replace text with substitutions.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("John sold a car to Paul.");
builder.Writeln("Jane sold a house to Joe.");

// Perform a find-and-replace operation on a range's text contents
// while preserving some elements from the replaced text using substitutions.
FindReplaceOptions options = new FindReplaceOptions();
options.UseSubstitutions = true;

Regex regex = new Regex(@"([A-z]+) sold a ([A-z]+) to ([A-z]+)");
doc.Range.Replace(regex, @"$3 bought a $2 from $1", options);

Assert.AreEqual(doc.GetText(), "Paul bought a car from John.\rJoe bought a house from Jane.\r\f");

ExpandedSee Also