Replacer
Inheritance: java.lang.Object
public class Replacer
Provides methods intended to find and replace text in the document.
Methods
replace(InputStream inputStream, OutputStream outputStream, int saveFormat, String pattern, String replacement)
public static int replace(InputStream inputStream, OutputStream outputStream, int saveFormat, String pattern, String replacement)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveFormat | int | |
pattern | java.lang.String | |
replacement | java.lang.String |
Returns: int
replace(InputStream inputStream, OutputStream outputStream, int saveFormat, String pattern, String replacement, FindReplaceOptions options)
public static int replace(InputStream inputStream, OutputStream outputStream, int saveFormat, String pattern, String replacement, FindReplaceOptions options)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveFormat | int | |
pattern | java.lang.String | |
replacement | java.lang.String | |
options | FindReplaceOptions |
Returns: int
replace(InputStream inputStream, OutputStream outputStream, int saveFormat, Pattern pattern, String replacement)
public static int replace(InputStream inputStream, OutputStream outputStream, int saveFormat, Pattern pattern, String replacement)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveFormat | int | |
pattern | java.util.regex.Pattern | |
replacement | java.lang.String |
Returns: int
replace(InputStream inputStream, OutputStream outputStream, int saveFormat, Pattern pattern, String replacement, FindReplaceOptions options)
public static int replace(InputStream inputStream, OutputStream outputStream, int saveFormat, Pattern pattern, String replacement, FindReplaceOptions options)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveFormat | int | |
pattern | java.util.regex.Pattern | |
replacement | java.lang.String | |
options | FindReplaceOptions |
Returns: int
replace(String inputFileName, String outputFileName, int saveFormat, String pattern, String replacement)
public static int replace(String inputFileName, String outputFileName, int saveFormat, String pattern, String replacement)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFileName | java.lang.String | |
outputFileName | java.lang.String | |
saveFormat | int | |
pattern | java.lang.String | |
replacement | java.lang.String |
Returns: int
replace(String inputFileName, String outputFileName, int saveFormat, String pattern, String replacement, FindReplaceOptions options)
public static int replace(String inputFileName, String outputFileName, int saveFormat, String pattern, String replacement, FindReplaceOptions options)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFileName | java.lang.String | |
outputFileName | java.lang.String | |
saveFormat | int | |
pattern | java.lang.String | |
replacement | java.lang.String | |
options | FindReplaceOptions |
Returns: int
replace(String inputFileName, String outputFileName, int saveFormat, Pattern pattern, String replacement)
public static int replace(String inputFileName, String outputFileName, int saveFormat, Pattern pattern, String replacement)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFileName | java.lang.String | |
outputFileName | java.lang.String | |
saveFormat | int | |
pattern | java.util.regex.Pattern | |
replacement | java.lang.String |
Returns: int
replace(String inputFileName, String outputFileName, int saveFormat, Pattern pattern, String replacement, FindReplaceOptions options)
public static int replace(String inputFileName, String outputFileName, int saveFormat, Pattern pattern, String replacement, FindReplaceOptions options)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFileName | java.lang.String | |
outputFileName | java.lang.String | |
saveFormat | int | |
pattern | java.util.regex.Pattern | |
replacement | java.lang.String | |
options | FindReplaceOptions |
Returns: int
replace(String inputFileName, String outputFileName, String pattern, String replacement)
public static int replace(String inputFileName, String outputFileName, String pattern, String replacement)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file.
Examples:
Shows how to replace string in the document.
// There is a several ways to replace string in the document:
String doc = getMyDir() + "Footer.docx";
String pattern = "(C)2006 Aspose Pty Ltd.";
String replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
Replacer.replace(doc, getArtifactsDir() + "LowCode.Replace.1.docx", pattern, replacement);
Replacer.replace(doc, getArtifactsDir() + "LowCode.Replace.2.docx", SaveFormat.DOCX, pattern, replacement);
FindReplaceOptions options = new FindReplaceOptions();
options.setFindWholeWordsOnly(false);
Replacer.replace(doc, getArtifactsDir() + "LowCode.Replace.3.docx", SaveFormat.DOCX, pattern, replacement, options);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFileName | java.lang.String | The input file name. |
outputFileName | java.lang.String | The output file name. |
pattern | java.lang.String | A string to be replaced. |
replacement | java.lang.String | A string to replace all occurrences of pattern. |
Returns: int - The number of replacements made.
replace(String inputFileName, String outputFileName, Pattern pattern, String replacement)
public static int replace(String inputFileName, String outputFileName, Pattern pattern, String replacement)
Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression.
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 = getMyDir() + "Footer.docx";
String pattern = "gr(a|e)y";
String replacement = "lavender";
Replacer.replace(doc, getArtifactsDir() + "LowCode.ReplaceRegex.1.docx", pattern, replacement);
Replacer.replace(doc, getArtifactsDir() + "LowCode.ReplaceRegex.2.docx", SaveFormat.DOCX, pattern, replacement);
FindReplaceOptions options = new FindReplaceOptions();
options.setFindWholeWordsOnly(false);
Replacer.replace(doc, getArtifactsDir() + "LowCode.ReplaceRegex.3.docx", SaveFormat.DOCX, pattern, replacement, options);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFileName | java.lang.String | The input file name. |
outputFileName | java.lang.String | The output file name. |
pattern | java.util.regex.Pattern | A regular expression pattern used to find matches. |
replacement | java.lang.String | A string to replace all occurrences of pattern. |
Returns: int - The number of replacements made.