Class ReplacerContext
Namespace: Aspose.Words.LowCode
Assembly: Aspose.Words.dll (25.12.0)
Find/replace operation context.
public class ReplacerContext : ProcessorContextInheritance
object ← ProcessorContext ← ReplacerContext
Inherited Members
ProcessorContext.WarningCallback , ProcessorContext.FontSettings , ProcessorContext.LayoutOptions , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
Shows how to replace string with regex in the document using context.
// There is a several ways to replace string with regex in the document:
string doc = MyDir + "Footer.docx";
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContextRegex.docx")
.Execute();Shows how to replace string in the document using context.
// There is a several ways to replace string in the document:
string doc = MyDir + "Footer.docx";
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContext.docx")
.Execute();Shows how to replace string in the document using documents from the stream using context.
// There is a several ways to replace string in the document using documents from the stream:
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
using (FileStream streamIn = new FileStream(MyDir + "Footer.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStream.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Shows how to replace string with regex in the document using documents from the stream using context.
// There is a several ways to replace string with regex in the document using documents from the stream:
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
using (FileStream streamIn = new FileStream(MyDir + "Replace regex.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStreamRegex.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Constructors
ReplacerContext()
public ReplacerContext()Properties
FindReplaceOptions
Find/replace options.
public FindReplaceOptions FindReplaceOptions { get; }Property Value
Examples
Shows how to replace string with regex in the document using context.
// There is a several ways to replace string with regex in the document:
string doc = MyDir + "Footer.docx";
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContextRegex.docx")
.Execute();Shows how to replace string in the document using context.
// There is a several ways to replace string in the document:
string doc = MyDir + "Footer.docx";
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContext.docx")
.Execute();Shows how to replace string in the document using documents from the stream using context.
// There is a several ways to replace string in the document using documents from the stream:
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
using (FileStream streamIn = new FileStream(MyDir + "Footer.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStream.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Shows how to replace string with regex in the document using documents from the stream using context.
// There is a several ways to replace string with regex in the document using documents from the stream:
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
using (FileStream streamIn = new FileStream(MyDir + "Replace regex.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStreamRegex.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Methods
SetReplacement(string, string)
Sets pattern and replacement used by find/replace operation.
public void SetReplacement(string pattern, string replacement)Parameters
pattern string
replacement string
Examples
Shows how to replace string in the document using context.
// There is a several ways to replace string in the document:
string doc = MyDir + "Footer.docx";
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContext.docx")
.Execute();Shows how to replace string in the document using documents from the stream using context.
// There is a several ways to replace string in the document using documents from the stream:
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
using (FileStream streamIn = new FileStream(MyDir + "Footer.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStream.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Remarks
Using this method overrides previously set pattern and replacement.
SetReplacement(Regex, string)
Sets pattern and replacement used by find/replace operation.
public void SetReplacement(Regex pattern, string replacement)Parameters
pattern Regex
replacement string
Examples
Shows how to replace string with regex in the document using context.
// There is a several ways to replace string with regex in the document:
string doc = MyDir + "Footer.docx";
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContextRegex.docx")
.Execute();Shows how to replace string with regex in the document using documents from the stream using context.
// There is a several ways to replace string with regex in the document using documents from the stream:
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
using (FileStream streamIn = new FileStream(MyDir + "Replace regex.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStreamRegex.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Remarks
Using this method overrides previously set pattern and replacement.