Class Replacer
Namespace: Aspose.Words.LowCode
Assembly: Aspose.Words.dll (25.12.0)
Provides methods intended to find and replace text in the document.
public class Replacer : ProcessorInheritance
Inherited Members
Processor.mResultDocument , Processor.From(string) , Processor.From(string, LoadOptions) , Processor.From(Stream) , Processor.From(Stream, LoadOptions) , Processor.To(string) , Processor.To(string, SaveOptions) , Processor.To(string, SaveFormat) , Processor.To(Stream, SaveOptions) , Processor.To(Stream, SaveFormat) , Processor.To(List<Stream>, SaveOptions) , Processor.To(List<Stream>, SaveFormat) , Processor.Execute() , Processor.Execute(CancellationToken) , Processor.ExecuteCore() , Processor.CheckArgumentsSet() , Processor.GetPartFileName(string, int, SaveFormat) , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Methods
CheckArgumentsSet()
protected override void CheckArgumentsSet()Create(ReplacerContext)
Creates new instance of the replacer processor.
public static Replacer Create(ReplacerContext context)Parameters
context ReplacerContext
Returns
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();
}ExecuteCore()
protected override void ExecuteCore()Replace(string, string, string, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file.
public static int Replace(string inputFileName, string outputFileName, string pattern, string replacement)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Examples
Shows how to replace string in the document.
// 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.";
FindReplaceOptions options = new FindReplaceOptions();
options.FindWholeWordsOnly = false;
Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.1.docx", pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.2.docx", SaveFormat.Docx, pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.3.docx", SaveFormat.Docx, pattern, replacement, options);Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveFormat, string, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveFormat saveFormat, string pattern, string replacement)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveFormat SaveFormat
The save format.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveFormat, string, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveFormat saveFormat, string pattern, string replacement, FindReplaceOptions options)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveFormat SaveFormat
The save format.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Examples
Shows how to replace string in the document.
// 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.";
FindReplaceOptions options = new FindReplaceOptions();
options.FindWholeWordsOnly = false;
Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.1.docx", pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.2.docx", SaveFormat.Docx, pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.Replace.3.docx", SaveFormat.Docx, pattern, replacement, options);Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveOptions, string, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveOptions saveOptions, string pattern, string replacement)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveOptions, string, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveOptions saveOptions, string pattern, string replacement, FindReplaceOptions options)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(Stream, Stream, SaveFormat, string, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveFormat saveFormat, string pattern, string replacement)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveFormat SaveFormat
The save format.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
Replace(Stream, Stream, SaveFormat, string, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveFormat saveFormat, string pattern, string replacement, FindReplaceOptions options)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveFormat SaveFormat
The save format.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Examples
Shows how to replace string in the document using documents from the stream.
// 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))
{
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStream.1.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement);
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStream.2.docx", FileMode.Create, FileAccess.ReadWrite))
{
FindReplaceOptions options = new FindReplaceOptions();
options.FindWholeWordsOnly = false;
Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement, options);
}
}Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
Replace(Stream, Stream, SaveOptions, string, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveOptions saveOptions, string pattern, string replacement)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveOptions SaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
Replace(Stream, Stream, SaveOptions, string, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveOptions saveOptions, string pattern, string replacement, FindReplaceOptions options)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveOptions SaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
Replace(string, string, Regex, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression.
public static int Replace(string inputFileName, string outputFileName, Regex pattern, string replacement)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Examples
Shows how to replace string with regex in the document.
// 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";
Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.1.docx", pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.2.docx", SaveFormat.Docx, pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.3.docx", SaveFormat.Docx, pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false });Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveFormat, Regex, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveFormat saveFormat, Regex pattern, string replacement)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveFormat SaveFormat
The save format.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveFormat, Regex, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveFormat saveFormat, Regex pattern, string replacement, FindReplaceOptions options)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveFormat SaveFormat
The save format.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Examples
Shows how to replace string with regex in the document.
// 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";
Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.1.docx", pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.2.docx", SaveFormat.Docx, pattern, replacement);
Replacer.Replace(doc, ArtifactsDir + "LowCode.ReplaceRegex.3.docx", SaveFormat.Docx, pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false });Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveOptions, Regex, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveOptions saveOptions, Regex pattern, string replacement)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(string, string, SaveOptions, Regex, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression, with the specified save format and additional options.
public static int Replace(string inputFileName, string outputFileName, SaveOptions saveOptions, Regex pattern, string replacement, FindReplaceOptions options)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Replace(Stream, Stream, SaveFormat, Regex, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream using a regular expression, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveFormat saveFormat, Regex pattern, string replacement, FindReplaceOptions options)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveFormat SaveFormat
The save format.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Examples
Shows how to replace string with regex in the document using documents from the stream.
// 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))
{
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStreamRegex.1.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement);
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceStreamRegex.2.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Replace(streamIn, streamOut, SaveFormat.Docx, pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false });
}Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
Replace(Stream, Stream, SaveFormat, Regex, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream using a regular expression, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveFormat saveFormat, Regex pattern, string replacement)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveFormat SaveFormat
The save format.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
Replace(Stream, Stream, SaveOptions, Regex, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream using a regular expression, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveOptions saveOptions, Regex pattern, string replacement, FindReplaceOptions options)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveOptions SaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
Replace(Stream, Stream, SaveOptions, Regex, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input stream using a regular expression, with the specified save format and additional options.
public static int Replace(Stream inputStream, Stream outputStream, SaveOptions saveOptions, Regex pattern, string replacement)Parameters
inputStream Stream
The input stream.
outputStream Stream
The output stream.
saveOptions SaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
Returns
The number of replacements made.
Remarks
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.
ReplaceToImages(string, ImageSaveOptions, string, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, string pattern, string replacement)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
Returns
Stream []
ReplaceToImages(string, ImageSaveOptions, string, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, string pattern, string replacement, FindReplaceOptions options)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
Stream []
Examples
Shows how to replace string in the document and save result to images.
// 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.";
Stream[] images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);
FindReplaceOptions options = new FindReplaceOptions();
options.FindWholeWordsOnly = false;
images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, options);ReplaceToImages(Stream, ImageSaveOptions, string, string)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, string pattern, string replacement)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
Returns
Stream []
ReplaceToImages(Stream, ImageSaveOptions, string, string, FindReplaceOptions)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, string pattern, string replacement, FindReplaceOptions options)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The save options.
pattern string
A string to be replaced.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
Stream []
Examples
Shows how to replace string in the document using documents from the stream and save result to images.
// 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))
{
Stream[] images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);
FindReplaceOptions options = new FindReplaceOptions();
options.FindWholeWordsOnly = false;
images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, options);
}ReplaceToImages(string, ImageSaveOptions, Regex, string, FindReplaceOptions)
Replaces all occurrences of a specified regular expression pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, Regex pattern, string replacement, FindReplaceOptions options)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
Stream []
Examples
Shows how to replace string with regex in the document and save result to images.
// 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";
Stream[] images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);
images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false });ReplaceToImages(string, ImageSaveOptions, Regex, string)
Replaces all occurrences of a specified regular expression pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, Regex pattern, string replacement)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
Returns
Stream []
ReplaceToImages(Stream, ImageSaveOptions, Regex, string, FindReplaceOptions)
Replaces all occurrences of a specified regular expression pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, Regex pattern, string replacement, FindReplaceOptions options)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
options FindReplaceOptions
Aspose.Words.Replacing.FindReplaceOptions object to specify additional options.
Returns
Stream []
Examples
Shows how to replace string with regex in the document using documents from the stream and save result to images.
// 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))
{
Stream[] images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);
images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false });
}ReplaceToImages(Stream, ImageSaveOptions, Regex, string)
Replaces all occurrences of a specified regular expression pattern with a replacement string in the input file. Renders output to images.
public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, Regex pattern, string replacement)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The save options.
pattern Regex
A regular expression pattern used to find matches.
replacement string
A string to replace all occurrences of pattern.
Returns
Stream []